We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Outlook mail - image in body

Hello - I am evaluating Aspose for sending email and have question on embedding images and wondering if it is possible.

Hi Dawn,

Thank you for writing to Aspose support team.

You can use Aspose.Email for .NET to create an email with embedded image in the body and then send it using SmtpClient or ExchangeClient. Please have a look at the following code sample for working with MailMessage and embedding inline image in the body.

Sample Code:

//Create an instance of the MailMessage class

MailMessage mail = new MailMessage();

//Set the addresses

mail.From = new MailAddress("test001@kerio.com");

mail.To.Add("test001@kerio.com");

//Set the content

mail.Subject = “This is an email”;

//Create the plain text part

//It is viewable by those clients that don’t support HTML

AlternateView plainView = AlternateView.CreateAlternateViewFromString(“This is my plain text content”, null, “text/plain”);

//Create the HTML part.

//To embed images, we need to use the prefix ‘cid’ in the img src value.

//The cid value will map to the Content-Id of a Linked resource.

//Thus will map to a LinkedResource with a ContentId of //‘companylogo’.

AlternateView htmlView = AlternateView.CreateAlternateViewFromString(“Here is an embedded image.”, null, “text/html”);

//create the LinkedResource (embedded image)

LinkedResource logo = new LinkedResource(@“D:\Personalization.png”, MediaTypeNames.Image.Png);

logo.ContentId = “companylogo”;

//Add the LinkedResource to the appropriate view

mail.LinkedResources.Add(logo);

mail.AlternateViews.Add(plainView);

mail.AlternateViews.Add(htmlView);

Once the email message is ready, you can send it using the SmtpClient or ExchangeClient. Please follow these links for further information on Working with our SMTP and Exchange clients and let us know if we can be of any additional help to you in this regard.