Using EASendMail SMTP Windows 8/10 Runtime Component in Windows Store Apps


Add Reference of EASendMail to Visual Stuido 2012 or later Project

To use EASendMail SMTP Component in your Windows Store App project, the first step is "Add reference of EASendMail to your project". Please create/open your project with Visual Studio.NET, then choose menu->"Project"->"Add Reference"->".NET"->"Browse...", and choose the "Installation Path\Lib\[portable* or uap]\EASendMail.winmd" from your disk, click "Open"->"OK", the reference of EASendMail will be added to your project, and you can start to use EASendMail SMTP Component in your project.

SMTP Component for Windows Store App

Deploying EASendMail with Application

After compiling your project, a copy of EASendMail.winmd will be generated by compiler in same folder of your application executable file. Packing all the *.winmd, *.dll and *.exe in the folder to installer is ok. As EASendMail.winmd is a pure Windows 8 Runtime Component, it doesn't require "Regsvr32" (self-register) to register the dll.

Seperate builds of run-time assembly for Windows Run Time

File .NET Framework Version
Lib\uap10.0\EASendMail.winmd Built with Universal Windows Platform.
It requires Windows 10 or later version (Universal Windows Platform).

Mail Address Syntax

For single email address (From), the syntax can be ["][display name]["]<email address>.
For example, "Tester, T" <test@adminsystem.com>, Tester <test@adminsystem.com>, <test@adminsystem.com> or test@adminsystem.com.

For mulitple email address (To, CC, Bcc), the syntax can be [single email],[single email]... (,;\r\n) can be used to separate multiple email addresses.
For example: "Tester, T" <test1@adminsystem.com>, Tester2 <test2@adminsystem.com>, <test3@adminsystem.com>, test4@adminsystem.com

Server Address Syntax

The server syntax is [server ip or domain] [port]. SPACE is used to separate server address and port. If port is not specified, default port 25 will be used.
For example: localhost 25 or localhost.

Example

[Visual Basic, C#, JScript] The following example demonstrates how to send email in Windows 8 Store App, but it doesn't demonstrates the events usage. 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");

        // Add recipient email address, please change it to yours
        oMail.To.Add(new MailAddress("support@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")

        ' Add recipient email address, please change it to yours
        oMail.To.Add(New MailAddress("support@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");

    // Add recipient email address, please change it to yours
    oMail.to.add(new EASendMail.MailAddress("support@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

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

Online Tutorials

Send Email in VB - Windows Store App
Send Email in C# - Windows Store App
Send Email in JavaScript - Windows Store App
Send Email in VB 6.0 - Tutorial
Send Email in C# - Tutorial
Send Email in VB.NET - Tutorial
Send Email in Visual C++ - Tutorial
Send Email in Managed C++/CLI - Tutorial
Send Email in Delphi - Tutorial
Send Email in MS SQL stored procedure - Tutorial