2017-03-07 74 views
0

我试图通过电子邮件使用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("[email protected]"); 
    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

回答

0
src=\"cid:LogoPicture\" 

阅读的同时改变

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

所以\迹象肯定前cess