ComponentPro UltimateMail

Creating an e-mail message containing embedded resources

Language Filter: AllSend comments on this topic to ComponentPro

The code snippet below shows you how to create an e-mail message and add an image from local disk as a LinkedResource object:

using System;
using ComponentPro.Net.Mail;

...

// Create a new instance of the MailMessage class.
MailMessage msg = new MailMessage();

// Add from address.
msg.From.Add("fromemail@domain.com");
// Add recipient.
msg.To.Add("fromemail@domain.com");
// Set subject.
msg.Subject = "MHT message";
// ImageTypeName's src is linked to an embedded image.
msg.BodyHtml = "Below is an attached image:<br><img src='cid:myimage'>";
// Create a LinkedResource object.
LinkedResource lr = new LinkedResource("c:\\myfolder\\myimage.jpg", MediaTypeNames.Image.Jpeg);
lr.ContentIdentifier = "myimage";
msg.LinkedResources.Add(lr);

// Connect, login and send the message here. 
// the following code demonstrates how to do that:
Smtp client = new Smtp();
client.Connect("servername");
client.Authenticate("username", "password");
client.Send(msg);
client.Disconnect();

// ...