SmtpMail Class


Provides properties and methods for constructing an e-mail message.

System.Object
    EASendMail.SmtpMail

[Visual Basic]
Public Class SmtpMail
[C#]
public class SmtpMail
[C++]
public ref class SmtpMail
[JScript]
public class SmtpMail

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Public Constructors

SmtpMail Constructor Initializes a new instance of the SmtpMail class.

Public Properties

AutoCalendar Specifies the e-mail generates text/calendar body with ics attachment automatically.
AutoTextBody Specifies the e-mail generates alternative text body for_c.html body automatically.
Bcc Gets or sets a AddressCollection of e-mail addresses that receive a blind carbon copy (BCC) of the e-mail message.
Cc Gets or sets a AddressCollection of e-mail addresses that receive a carbon copy (CC) of the e-mail message.
Charset Gets or sets the charset of the e-mail message.
Date Gets or sets the date time of the e-mail message.
DeliveryNotification Gets or sets the delivery notifications for this e-mail message.
EncodedContent Gets the encoded email content.
From Gets or sets the original e-mail address of the sender.
HeaderEncoding Gets or sets the encoding for subject and friendly name in From, To, Cc.
Headers Gets the HeaderCollection for headers of the e-mail message.
HtmlBody Gets or sets the html body of the e-mail message.
Mailer Gets or sets the "X-Mailer" of the e-mail message.
MessageID Gets the Message-ID of the e-mail message.
MimeParts Gets the MimePartCollection of the e-mail message.
Priority Gets or sets the priority of the e-mail message.
ReadReceipt Sets the read receipt request in the email.
Recipients Gets a AddressCollection for all e-mail receivers (To, Cc, Bcc).
ReplyTo Gets or sets the e-mail address of the reply address.
ReturnPath Gets or sets the e-mail address of the delivery report address.
Sender Gets or sets the sender of the e-mail message.
Subject Gets or sets the subject of the e-mail message.
TextBody Gets or sets the text body of the e-mail message.
To Gets or sets a AddressCollection of recipient e-mail addresses.
TransferEncoding Gets or sets encoding for the body text of the e-mail message.

Public Methods

AddAttachment Attaches a file from binary array to the e-mail message.
AddAttachmentAsync Attaches a file from local disk or remote URL to the e-mail message.
ClearAttachments Clears all the file attachments of the e-mail message.
LoadMessage Loads a RFC822 message (*.eml) file from binary data array to current SmtpMail instance.
LoadMessageAsync Loads a RFC822 message (*.eml) file to current SmtpMail instance.
ImportHtmlAsync Imports html source from string to html body of the e-mail message.
ImportHtmlBodyAsync Imports html source from file or remote website to html body of the e-mail message.
ImportTextBodyAsync Imports text source from file or remote website to text body of the e-mail message.
RemoveAttachment Removes file attachment from the e-mail message by file name.
Reset Resets the From, To, Cc, Bcc, Subject, TextBody,_c.htmlBody, Message-ID and Date of the e-mail message.
SaveAsAsync Saves the e-mail message to a file (*.eml file).

Examples

[Visual Basic, C#, JavaScript] The following example demonstrates how to send email in Windows 8 Store App. To get the full samples of EASendMail, please refer to Samples section.

[C# - Send Email from Windows Store Apps - XAML]
using EASendMail;
using System.Threading.Tasks;

private async Task SendEmail()
{
    String Result = "";
    try
    {
        SmtpMail oMail = new SmtpMail("TryIt");
        SmtpClient oSmtp = new SmtpClient();

        // Set sender email address, please change it to yours 
        oMail.From = new MailAddress("test@emailarchitect.net");

        // Specify sender address and display name
        // oMail.From = new MailAddress( "Tester", "test@emailarchitect.net" );
        // oMail.From = new MailAddress( "Tester<emailarchitect.net>" );

        // Add recipient email address, please change it to yours
        oMail.To.Add(new MailAddress("support@emailarchitect.net"));

        // Specify multiple recipients directly
        // oMail.To = new AddressCollection( "Tester1<test@emailarchitect.net>, Tester2<test2@emailarchitect.net>");		

        // Add more recipient email address
        // oMail.To.Add(new MailAddress("supportex@emailarchitect.net"));

        // Add CC recipient email address
        // oMail.Cc.Add(new MailAddress("cc@emailarchitect.net"));

        // Add BCC recipient email address
        // oMail.Bcc.Add(new MailAddress("cc@emailarchitect.net"));

        // Set email subject
        oMail.Subject = "test email from C# XAML project";

        // Set email body
        oMail.TextBody = "this is a test email sent from Windows Store App, do not reply";

        // Your SMTP server address
        SmtpServer oServer = new SmtpServer("smtp.emailarchitect.net");

        // User and password for ESMTP authentication            
        oServer.User = "test@emailarchitect.net";
        oServer.Password = "testpassword";

        // If your SMTP server requires TLS connection on 25 port, please add this line
        // oServer.ConnectType = SmtpConnectType.ConnectSSLAuto;

        // If your SMTP server requires SSL connection on 465 port, please add this line
        // oServer.Port = 465;
        // oServer.ConnectType = SmtpConnectType.ConnectSSLAuto;

        await oSmtp.SendMailAsync(oServer, oMail);
        Result = "Email was sent successfully!";
    }
    catch (Exception ep)
    {
        Result = String.Format("Failed to send email with the following error: {0}", ep.Message);
    }

    // Display Result by Diaglog box
    Windows.UI.Popups.MessageDialog dlg = new
        Windows.UI.Popups.MessageDialog(Result);
           
    await dlg.ShowAsync();
}

[VB - Send Email from Windows Store Apps - XAML]
Imports EASendMail

Private Async Function SendEmail() As Task
    Dim Result As String = ""
    Try

        Dim oMail As New SmtpMail("TryIt")
        Dim oSmtp As New SmtpClient()

        ' Set sender email address, please change it to yours
        oMail.From = New MailAddress("test@emailarchitect.net")

        ' Specify sender address and display name
        ' oMail.From = New MailAddress( "Tester", "test@emailarchitect.net" )
        ' oMail.From = New MailAddress( "Tester<emailarchitect.net>" )

        ' Add recipient email address, please change it to yours
        oMail.To.Add(New MailAddress("support@emailarchitect.net"))

        ' Specify multiple recipients directly
        ' oMail.To = New AddressCollection( "Tester1<test@emailarchitect.net>, Tester2<test2@emailarchitect.net>")

        ' Add more recipient email address
        ' oMail.To.Add(New MailAddress("supportex@emailarchitect.net"))

        ' Add CC recipient email address
       ' oMail.Cc.Add(New MailAddress("cc@emailarchitect.net"))

        ' Add BCC recipient email address
        ' oMail.Bcc.Add(New MailAddress("cc@emailarchitect.net"))

        ' Set email subject
        oMail.Subject = "test email from VB XAML project"

        ' Set email body
        oMail.TextBody = "this is a test email sent from Windows Store App, do not reply"

        ' Your SMTP server address
        Dim oServer As New SmtpServer("smtp.emailarchitect.net")

        ' User and password for ESMTP authentication            
        oServer.User = "test@emailarchitect.net"
        oServer.Password = "testpassword"

        ' If your SMTP server requires TLS connection on 25 port, please add this line
        ' oServer.ConnectType = SmtpConnectType.ConnectSSLAuto

        ' If your SMTP server requires SSL connection on 465 port, please add this line
        ' oServer.Port = 465
        ' oServer.ConnectType = SmtpConnectType.ConnectSSLAuto

        Await oSmtp.SendMailAsync(oServer, oMail)
        Result = "Email was sent successfully!"

    Catch ep As Exception
        Result = String.Format("Failed to send email with the following error: {0}", ep.Message)
    End Try

    ' Display Result by Diaglog box
    Dim dlg As New Windows.UI.Popups.MessageDialog(Result)
    Await dlg.ShowAsync()
End Function

[JavaScript - Send Email from Windows Store Apps - HTML5]
function sendMail() {
    var result = "";

    var oMail = new EASendMail.SmtpMail("TryIt");
    var oSmtp = new EASendMail.SmtpClient();

    // Set sender email address, please change it to yours 
    oMail.from = new EASendMail.MailAddress("test@emailarchitect.net");

    // Specify sender address and display name
    // oMail.from = new EASendMail.MailAddress( "Tester", "test@emailarchitect.net" );
    // oMail.from = new EASendMail.MailAddress( "Tester<emailarchitect.net>" );

    // Add recipient email address, please change it to yours
    oMail.to.add(new EASendMail.MailAddress("support@emailarchitect.net"));

    // Specify multiple recipients directly
    // oMail.to = new EASendMail.AddressCollection( "Tester1<test@emailarchitect.net>, Tester2<test2@emailarchitect.net>");	

    // Add more recipient email address
    // oMail.to.add(new EASendMail.MailAddress("supportex@emailarchitect.net"));

    // Add CC recipient email address
    // oMail.cc.add(new EASendMail.MailAddress("cc@emailarchitect.net"));

    // Add BCC recipient email address
    // oMail.bcc.add(new EASendMail.MailAddress("cc@emailarchitect.net"));

    // Set email subject
    oMail.subject = "test email from JavaScript HTML5 project";

    // Set email body
    oMail.textBody = "this is a test email sent from Windows Store App, do not reply";

    // Your SMTP server address
    var oServer = new EASendMail.SmtpServer("smtp.emailarchitect.net");

    // User and password for ESMTP authentication            
    oServer.user = "test@emailarchitect.net";
    oServer.password = "testpassword";

    // If your SMTP server requires TLS connection on 25 port, please add this line
    // oServer.connectType = EASendMail.SmtpConnectType.connectSSLAuto;

    // If your SMTP server requires SSL connection on 465 port, please add this line
    // oServer.port = 465;
    // oServer.connectType = EASendMail.SmtpConnectType.connectSSLAuto;

    oSmtp.sendMailAsync(oServer, oMail).then(function (e) {
        result = "Email was sent successfully!";

        // Display Result by Diaglog box
        (new Windows.UI.Popups.MessageDialog(result, "Success")).showAsync();
    },

    function (e) {
        // because javascript exception only gives the stack trace messages, but it is not
        // real description of exception, so we give a property lastErrorMessage for javascript.
        if (oSmtp.lastErrorMessage != "") {
            result = oSmtp.lastErrorMessage;
        }
        else {
            result = e.message;
        }
        oSmtp.close();

        // Display Result by Diaglog box
        (new Windows.UI.Popups.MessageDialog(result, "Error Information")).showAsync();
    });
}

See Also

Using EASendMail Windows 8 Runtime Component
User Authentication and SSL Connection
From, ReplyTo, Sender and Return-Path
EASendMail Windows 8 Runtime Component References
EASendMail SMTP Component Samples