Click here to Skip to main content
15,880,608 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys, need help on sending an email on outlook. The email body is in html format and it has an embedded image inside it. My problem is when I received the email on outlook, all of the images are broken link.

C#
public static string getEmailFile(string file)
        {
            //string filename = Session["filename"].ToString();

            Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();

            //MailItem item = (MailItem)app.CreateItemFromTemplate(@"C:\Users\orculloj\Desktop\Sample3\" + filename, Type.Missing);
            //MailItem item = (MailItem)app.CreateItemFromTemplate(@"C:\Users\orculloj\Desktop\Sample3\Test.msg", Type.Missing);
            MailItem item = (MailItem)app.CreateItemFromTemplate(@"C:\Users\orculloj\Desktop\Sample2\20160101021244_5541.msg", Type.Missing);

            var a = item.HTMLBody;

            return a;
        }


What I have tried:

C#
Outlook.Application app = new Outlook.Application();

           MailItem item = (MailItem)app.CreateItemFromTemplate(@"C:\Users\orculloj\Desktop\Sample2\20160101021244_5541.msg", Type.Missing);

           string from = item.ReceivedOnBehalfOfName + "@altisource.com";

           //string body = item.HTMLBody;

           iframe1.Attributes["src"] = "Email.aspx";

           System.Net.Mail.MailMessage mailMsg = new System.Net.Mail.MailMessage();
           MailAddress mailAddress = new MailAddress(from);

           mailMsg.To.Add("JohnEmmanuel.Orcullo@altisource.com");

           mailMsg.From = mailAddress;

           // Subject and Body
           mailMsg.Subject = "Testing mail..";

           string x = "";

           mailMsg.IsBodyHtml = true;
           mailMsg.Body = getEmailFile(x);

           //SmtpMail.SmtpServer = "Internal-Mail.ascorp.com";
           SmtpClient smtpClient = new SmtpClient("Internal-Mail.ascorp.com");

           //smtpClient.EnableSsl = true;

           smtpClient.Send(mailMsg);
Posted
Updated 1-Apr-16 14:36pm
v2
Comments
Sergey Alexandrovich Kryukov 1-Apr-16 20:30pm    
I don't see where do you include images in your mail.
—SA

1 solution

I don't see where you include images in your mail. It has to be multi-part mail, some parts should be images. To reference images in HTML part, you have to use the special URI scheme (cid:), to reference a mail part. Please see my past answers:
Sending HTML attachment with images[^],
how can i send image with text in email in asp[^],
How to attach a file in smtp mail implementation[^],
Dynamically generate pdf file and Send an Email as a attachment.[^].

—SA
 
Share this answer
 
Comments
Member 11525563 6-Apr-16 15:17pm    
the images are embedded on the item.HTMLBody.
Sergey Alexandrovich Kryukov 6-Apr-16 17:28pm    
What makes you think so? Where?
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900