MailBee. NET Objects Tutorials

Sending a web page and HTML message with embedded pictures

In order to send an e-mail message with embedded objects, the developer should use the SMTP object. First of all, the developer should specify all the necessary properties of the SMTP object as described here.

In case an HTML-formatted message without any embedded objects is composed, the developer can use either SMTP.BodyHtmlText property or SMTP.Message.LoadBodyText method to set the message body.

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


oMailer.BodyHtmlText = @"<DIV>Test HTML message.</DIV><BR><BR>
        <FONT face=""Arial Black"" color=#0000ff size=5>
        <P align=left><STRONG><U>
        This is a test HTML mes-sage.
        <hr size=1>
        <a href=""""></a>";


oMailer.BodyHtmlText = "<DIV>Test HTML message.</DIV><BR><BR>" & vbCrLf & _
        "<FONT face= ""Arial Black"" color = #0000ff size = 5>" & vbCrLf & _
        "<P align=left><STRONG><U>" & vbCrLf & _
        "This is a test HTML mes-sage." & vbCrLf & _
        "</U></STRONG></P></FONT><p>" & vbCrLf & _
        "<hr size= 1>" & vbCrLf & _
        "<a href= """"></a>"

Another way is to use the SMTP.Message.LoadBodyText method. In this case, the developer is able to load a message from the specified URI as follows:


oMailer.Message.LoadBodyText(@"", MessageBodyType.Html);


oMailer.Message.LoadBodyText("", MessageBodyType.Html)



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


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

Otherwise, the developer should call the SMTP.Message.LoadBodyText method to compose a message with embedded objects (images, sounds or movies). The following sample loads the message body in default encoding along with all related files from the specified URI:


oMailer.Message.LoadBodyText(@" ", 
                Encoding.Default, ImportBodyOptions.ImportRelatedFiles|


oMailer.Message.LoadBodyText(" ", _
                MessageBodyType.Html, _
                Encoding.Default, ImportBodyOptions.ImportRelatedFiles Or _

Please note: when calling the SMTP.Message.LoadBodyText method, all related files will be attached to the message.

Should you experience any problems with the following sample, please see the corresponding topic of the Troubleshooting section.

Code Sample:

Summary: The following example creates a new message from the existing web page with the embedded objects and sends this message. Before using MailBee.NET Objects, please make sure it is unlocked (see "Sales, Licensing, and Support" and "Using MailBee.NET Objects in Your Projects" sections).


using System;
using System.Text;
using MailBee;
using MailBee.SmtpMail;
using MailBee.Mime;

namespace EmailApp
    class Class1
        static void Main(string[] args)
            Smtp oMailer = new Smtp();

            oMailer.To.AddFromString("Bill Smith <>");

            oMailer.From.AsString = "John Doe <> (Company Info)";

            oMailer.Subject = "Test web page";

            oMailer.Message.LoadBodyText(@"", MessageBodyType.Html, Encoding.Default, ImportBodyOptions.ImportRelatedFiles | ImportBodyOptions.ImportRelatedFilesFromUris);

                Console.WriteLine("The message has been successfully sent.");
            catch (MailBeeSmtpMessageSizeOutOfRangeException e)
                Console.WriteLine("The message is too large (more than " + e.MaxAllowedMessageSize + " bytes).");


Imports System
Imports System.Text
Imports MailBee
Imports MailBee.SmtpMail
Imports MailBee.Mime
Namespace EmailApp
    Class Class1
        <STAThread> _ 
        Shared  Sub Main(ByVal args() As String)
            Dim oMailer As Smtp =  New Smtp() 
            oMailer.To.AddFromString("Bill Smith <>")
            oMailer.From.AsString = "John Doe <> (Company Info)"
            oMailer.Subject = "Test web page"
            oMailer.Message.LoadBodyText("", MessageBodyType.Html, Encoding.Default, ImportBodyOptions.ImportRelatedFiles | ImportBodyOptions.ImportRelatedFilesFromUris)
                Console.WriteLine("The message has been successfully sent.")
            Catch e As MailBeeSmtpMessageSizeOutOfRangeException
                Console.WriteLine("The message is too large (more than " + e.MaxAllowedMessageSize + " bytes).")
            End Try
        End Sub
    End Class
End Namespace