MailBee. NET Objects Tutorials

Sending a web page and HTML message with embedded pictures

To send an e-mail message with embedded pictures, use SMTP class. First, set the SMTP server, account credentails and message headers as described here.

To set HTML body WITHOUT any embedded pictures, use SMTP.BodyHtmlText property. or to set the message body.

The use SMTP.BodyHtmlText property allows the developer to assign the body of a message directly as follows:

C#

oMailer.BodyHtmlText = @"<html><body><a href=""https://afterlogic.com"">afterlogic.com</a></body></html>";

VB.NET

oMailer.BodyHtmlText = "<html><body><a href=""https://afterlogic.com"">afterlogic.com</a></body></html>"

Another way is to use SMTP.Message.LoadBodyText method to load the message body from a file:

C#

oMailer.Message.LoadBodyText(@"C:\Temp\saved_web_page.htm", MessageBodyType.Html);

VB.NET

oMailer.Message.LoadBodyText("C:\Temp\saved_web_page.htm", MessageBodyType.Html)

To set HTML body WITH any embedded pictures, use another overload of SMTP.Message.LoadBodyText method (it also allows you to load the message body from a web page, not just from a local file:

C#

oMailer.Message.LoadBodyText(@"http://www.domain.com/index.htm", 
                MessageBodyType.Html,
                Encoding.Default, ImportBodyOptions.ImportRelatedFiles|
                ImportBodyOptions.ImportRelatedFilesFromUris);

VB.NET

oMailer.Message.LoadBodyText("http://www.domain.com/index.htm", _
                MessageBodyType.Html, _
                Encoding.Default, ImportBodyOptions.ImportRelatedFiles Or _
                ImportBodyOptions.ImportRelatedFilesFromUris)

The above code loads the message body from a web page and attaches all pictures (also scripts, CSS and other files mentioned on the page) as inline attachments.