Unable to send embedded image in email using FluentEmail

假装没事ソ 提交于 2019-12-04 05:29:10

You have to use a LinkedResource; have a look at this

using (LinkedResource image = new LinkedResource(@"c:\assets\image.jpg", "image/jpeg") { ContentId = "myimage" })
using (MailMessage mail = new MailMessage())
using (SmtpClient smtpClient = new SmtpClient())
{
    smtpClient.Host = "smtp.alfki.com";

    String body = @"
    <html>
        <head></head>
        <body>    
        <img src=""cid:myimage"" />      
        </body>
    </html>
    ";  

    AlternateView view = AlternateView.CreateAlternateViewFromString(body, null, "text/html");
    view.LinkedResources.Add(image);

    mail.IsBodyHtml = true;
    mail.AlternateViews.Add(view);
    mail.From = new MailAddress("John.Doe@alfki.com");
    mail.To.Add("Jane.Doe@alfki.com");
    mail.Subject = "An email with an inline image";

    smtpClient.Send(mail);
}

Edit:

It works in .NET Core/Standard.

I can not speak for FluentMail; maybe you can do without?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!