Материалы отфильтрованы по дате: апреля 2019
Вторник, 16 апреля 2019 03:36
Unity3D C# отправка Email в формате HTML с вложенной картинкой
Добрый день.
В продолжение темы об отправке Email из Unity на C#
Универсальное решение для всех почтовых клиентов подсмотрел здесь.
public static void SendMessageWithEmbeddedImages() { string htmlMessage = @"<html> <body> <img src='cid:EmbeddedContent_1' /> </body> </html>"; SmtpClient client = new SmtpClient("mail.server.com"); MailMessage msg = new MailMessage("Адрес электронной почты защищен от спам-ботов. Для просмотра адреса в вашем браузере должен быть включен Javascript.", "Адрес электронной почты защищен от спам-ботов. Для просмотра адреса в вашем браузере должен быть включен Javascript."); // Создаем HTML view AlternateView htmlView = AlternateView.CreateAlternateViewFromString( htmlMessage, Encoding.UTF8, MediaTypeNames.Text.Html); // Создаем текстовую альтернативу для почтовых клиентов, не поддерживающих HTML AlternateView plainView = AlternateView.CreateAlternateViewFromString( Regex.Replace(htmlMessage, "<[^>]+?>", string.Empty), Encoding.UTF8, MediaTypeNames.Text.Plain); string mediaType = MediaTypeNames.Image.Jpeg; LinkedResource img = new LinkedResource(@"C:\Images\MyImage.jpg", mediaType); // Обязательно установите все эти значения!!! img.ContentId = "EmbeddedContent_1"; img.ContentType.MediaType = mediaType; img.TransferEncoding = TransferEncoding.Base64; img.ContentType.Name = img.ContentId; img.ContentLink = new Uri("cid:" + img.ContentId); htmlView.LinkedResources.Add(img); ////////////////////////////////////////////////////////////// msg.AlternateViews.Add(plainView); msg.AlternateViews.Add(htmlView); msg.IsBodyHtml = true; msg.Subject = "Some subject"; client.Send(msg); }
Опубликовано в
Unity3D