-4

Hi all I'm in the middle of learning programming in school just to inform you and I wan't to learn in advance so here it is my problem is when sending email using fluent email, gmail won't show my embedded image and when I do inspect element it only show empty img tag but I can attach the image but unfortunately I can't embed the image inside the email body I did some research so far this is the result.

I'm using a template here and the image I'm sending is 90 x 90 and has jpg extension.

                string authorImage = HttpContext.Current.Server.MapPath(@"~/img/author.jpg");

                Attachment authorImageAtt = new Attachment(authorImage);

                authorImageAtt.ContentDisposition.Inline = true;
                authorImageAtt.ContentDisposition.DispositionType = DispositionTypeNames.Inline;

                string authorImageId = "author";
                authorImageAtt.ContentId = authorImageId;

                model.ImgSrc = authorImageId;

                var template =
                System.IO.File.ReadAllText(HttpContext.Current.Server.MapPath(string.Format("~/Templates/{0}.cshtml", emailTemplate)));
                var body = Razor.Parse(template, model);

                var email = Email
                .From("test@gmail.com")
                .To(model.EmailTo)
                .Subject(subject)
                .Attach(authorImageAtt)
                .Body(body).BodyAsHtml();
                email.Send();

The view.

@model MYAPP.Site.Models.Author

<h2>Image Below</h2>

<img src="cid:@Model.ImgSrc" />

What did I missed, I would be grateful to anyone can point me to the right path and also I'm in local development.

glen
  • 3
  • 1
  • 7

1 Answers1

0

As written in the comments by @Etienne (stackoverflow post)

mail.IsBodyHtml = true;

should suffice here.

Bryan
  • 91
  • 8