Warning: Creating default object from empty value in /var/www/u0668192/data/www/kuzevich.ru/components/com_k2/views/itemlist/view.html.php on line 743

Показать содержимое по тегу: embedded

Добрый день.

В продолжение темы об отправке 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