tags:

views:

156

answers:

1

Hi

I have a page that sends an email on ASP.NET MVC Page.

All the Text is displaying but the image is not displaying.

Any workaround.

Appreciate your responses.

Here is my code:

  MailMessage mailMsg = new MailMessage();
                    mailMsg.IsBodyHtml = true;
                    mailMsg.From = new MailAddress(ConfigurationManager.AppSettings["Email.Sender"]);
                    mailMsg.To.Add(new MailAddress(email));
                    mailMsg.Subject = "Test mail to display the Logo in the email";
                    mailMsg.Body = " Test mail to display the Logo in the email;
                    mailMsg.Body += Environment.NewLine + Environment.NewLine +
                        "<html><body><img src=cid:companylogo/><br></body></html>";

                    //Insert Logo
                    string logoPath = Server.MapPath(Links.Content.images.Amgen_MedInfo_Logo_jpg);    // logo is placed in images folder
                    LinkedResource logo = new LinkedResource(logoPath);
                    logo.ContentId = "companylogo";
                    // done HTML formatting in the next line to display logo
                    AlternateView aView = AlternateView.CreateAlternateViewFromString(mailMsg.Body, new System.Net.Mime.ContentType("text/html"));
                    aView.LinkedResources.Add(logo);
                    mailMsg.AlternateViews.Add(aView);
                    mailMsg.IsBodyHtml = true;

                    SmtpClient smtpClient = new SmtpClient(ConfigurationManager.AppSettings["SMTP"]);
                    smtpClient.Send(mailMsg);
+2  A: 

Have you checked the source of the received e-mail to see if the image is referenced correctly?

If it is then it's highly likely that the mail client is blocking the display of remote images.

ChrisF
I Checked the image and the path is referenced correctly.
Rita
@Rita - in that case I would suspect that the mail client is blocking it.
ChrisF
@ChrisF: mail clients by default blocks them to prevent the some kind of tricks like detecting whether mail was opened or not.
zerkms
@zerkms - I know!
ChrisF
@ChrisF: just wanted to be clear. sorry ;-)
zerkms
It works... some messy with Plain text and Image. This article helped me. http://forums.asp.net/p/1320392/2622898.aspx
Rita