The code snippet below shows you how to create an e-mail message and add an image from local disk as a LinkedResource object with ComponentSoft Mail library:
| C# | |
|---|---|
|
// 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", ImageTypeNames.Jpeg); lr.ContentIdentifier = "myimage"; msg.LinkedResources.Add(lr); // Connect, login and send the message here. // the following code demonstrates how to do that: // SmtpClient client = new SmtpClient(); // client.Connect("servername"); // client.Authenticate("username", "password"); // client.Send(msg); // client.Disconnect(); // ... | |
| VB.NET | |
|---|---|
|
' Create a new instance
of the MailMessage class. Dim msg As 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. Dim lr As New LinkedResource("c:\myfolder\myimage.jpg", ImageTypeNames.Jpeg) lr.ContentIdentifier = "myimage" msg.LinkedResources.Add(lr) ' Connect, login and send the message here. ' the following code demonstrates how to do that: ' SmtpClient client = new SmtpClient(); ' client.Connect("servername"); ' client.Authenticate("username", "password"); ' client.Send(msg); ' client.Disconnect(); ' ... | |
Recent Comments