为什么嵌入图片不会通过电子邮件发送

时间:2017-03-07 19:06:32

标签: c# email html-email

我尝试使用c#通过电子邮件发送图片,但是在消息中它是空的,尽管它已成功附加到电子邮件中。

public static void EmailActivateMessage(string email, string token, string id, string userName)
{
    LinkedResource resource = new LinkedResource(HttpContext.Current.Server.MapPath("~/Content/images/home/logo.gif"), MediaTypeNames.Image.Gif);
    resource.ContentId = "LogoPicture";

    AlternateView altView = AlternateView.CreateAlternateViewFromString(ActivationText(id, token, userName), null, MediaTypeNames.Text.Html);
    altView.LinkedResources.Add(resource);

    MailMessage mail = new MailMessage();
    SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
    smtp.EnableSsl = true;
    smtp.Credentials = new NetworkCredential("SquirrelsStore", "BusinessMoney");

    mail.From = new MailAddress("SquirrelsStore@gmail.com");
    mail.To.Add(email);
    mail.Subject = "Activation Mail";

    mail.AlternateViews.Add(altView);

    smtp.Send(mail);
}

这是图像为空的html的一部分

<tr> 
    <td style="font-family: sans-serif;font-size: 16px !important;vertical-align: top;">
        <img width="100" height="100" src=\"cid:LogoPicture\" style="border: none;-ms-interpolation-mode: bicubic;max-width: 100%;">
    </td>
    <td style="vertical-align: middle;font-family: sans-serif;font-size: 16px !important;">
       <a href="http://link.com" style="font-size: 40px;text-decoration: none; color: #fe980f; outline-style: none;">Текст</a>
   </td>
</tr>

enter image description here

1 个答案:

答案 0 :(得分:0)

src=\"cid:LogoPicture\" 

读取更改为

src=\\\"cid:LogoPicture\\\"

所以\标志肯定是多余的