SmtpClient.SendMailToQueueEx Method


Sends an e-mail message to specified instance of EASendMail Service.

[Visual Basic]
Public Sub SendMailToQueueEx( _
    instance As String, _
    server As SmtpServer, _
    mail As SmtpMail _
)
[C#]
public void SendMailToQueueEx(
    string instance,
    SmtpServer server,
    SmtpMail mail
);
[C++]
public: void SendMailToQueueEx(
    String^ instance,
    SmtpServer^ server,
    SmtpMail^ mail
);
[JScript]
public function SendMailToQueueEx( 
    instance : String,
    server : SmtpServer, 
    mail : SmtpMail
);

Parameters

instance
A String value used to specify EASendMail Service instance.
server
A SmtpServer instances used to send email. If this parameter is null (Nothing in Visual Basic), the email will be sent by the smtp server set in EASendMail Service.
mail
A SmtpMail instance to send.

Remarks

EASendMail Service is a light and fast email delivery service which works with EASendMail SMTP .Net Component / ANSMTP SMTP Component to enable your application to send mass emails in background service. Along with its ability to picking recipients from database in background and sending email in specified datetime, it eases your task in developing featured email application such as newsletter application. We strongly recommend you to use EASendMail Service with your ASP/Web Application. To learn more detail about SendMailToQueue method, please refer to Work with EASendMail Service (Email Queuing) section.
If your application is running on the same server of EASendMail Service, then please use SendMailToQueue or SendMailToQueueEx method; If your appliation want to send email to EASendMail Service on remote server, you should use PostToRemoteQueue method.

Example

[Visual Basic, C#] The following example demonstrates how to send email with EASendMail SMTP Component. To get the full samples of EASendMail, please refer to Samples section.

[VB - Send Email to Queue]

Imports EASendMail

Public Sub SendMailToQueue(sender As String,
    recipient As String,
    subject As String)

    Try
        Dim oMail As SmtpMail = New SmtpMail("TryIt")
        oMail.From = New MailAddress(sender)
        ' Separate multiple addresses by comma(,)
        oMail.To = New AddressCollection(recipient)

        ' To avoid too many email addresses appear in To header, using the
        ' following code only display the current recipient
        oMail.Headers.ReplaceHeader("To", """{$var_rcptname}"" <{$var_rcptaddr}>")
        oMail.Headers.ReplaceHeader("X-Rcpt-To", 
                        oMail.To.ToEncodedString(HeaderEncodingType.EncodingAuto, "utf-8"))

        oMail.Subject = subject
        oMail.TextBody = "Dear {$var_rcptname}, your email address is {$var_rcptaddr}"

        ' If you want EASendMail service to send the email after 10 minutes, use the following code. 
        ' you can also cancel the scheduled task in EASendMail Service Manager->Queue Monitor->Scheduled Tasks 
        ' oMail.Date = System.DateTime.Now.AddMinutes(10)

        ' Your SMTP server address, if you don't set server, 
        ' EASendMail service uses the server setting in EASendMail Service Manager.
        Dim oServer As New SmtpServer("smtp.emailarchitect.net")

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

        ' If server supports SSL/TLS connection, SSL/TLS is used automatically.
        oServer.ConnectType = SmtpConnectType.ConnectTryTLS

        Dim oSmtp As SmtpClient = New SmtpClient()
        oSmtp.SendMailToQueueEx("myinstance", oServer, oMail)

        ' If you want to use SMTP server setting in EASendMail Service Manager, use
        ' oSmtp.SendMailToQueueEx("myinstance", Nothing, oMail)
        Console.WriteLine("The message was sent to EASendMail Service successfully!")

    Catch exp As Exception
        Console.WriteLine("Exception: Common: {0}, please make sure you installed EASendMail Service on the server!", exp.Message)
    End Try

End Sub


[C# - Send Email to Queue] using System; using System.Collections; using EASendMail; public void SendMailToQueue(string sender, string recipient, string subject) { try { SmtpMail oMail = new SmtpMail("TryIt"); oMail.From = sender; // Separate multiple addresses by comma(,) oMail.To = recipient; // To avoid too many email addresses appear in To header, // use following code only display the current recipient oMail.Headers.ReplaceHeader("To", "\"{$var_rcptname}\" <{$var_rcptaddr}>"); oMail.Headers.ReplaceHeader("X-Rcpt-To", oMail.To.ToEncodedString(HeaderEncodingType.EncodingAuto, "utf-8")); oMail.Subject = subject; oMail.TextBody = "Dear {$var_rcptname}, your email address is {$var_rcptaddr}"; // If you want EASendMail service to send the email after 10 minutes, use the following code. // you can also cancel the scheduled task in EASendMail Service Manager->Queue Monitor->Scheduled Tasks // oMail.Date = DateTime.Now.AddMinutes(10); // Your SMTP server address, if you don't set server, // EASendMail service uses the server setting in EASendMail Service Manager. SmtpServer oServer = new SmtpServer("smtp.emailarchitect.net"); // User and password for ESMTP authentication oServer.User = "test@emailarchitect.net"; oServer.Password = "test"; // Most mordern SMTP servers require SSL/TLS connection now. // ConnectTryTLS means if server supports SSL/TLS, SSL/TLS will be used automatically. oServer.ConnectType = SmtpConnectType.ConnectTryTLS; SmtpClient oSmtp = new SmtpClient(); oSmtp.SendMailToQueueEx("myinstance", oServer, oMail); // If you want to use SMTP server setting in EASendMail Service Manager, use // oSmtp.SendMailToQueueEx("myinstance", null, oMail); Console.WriteLine("The message was sent to EASendMail Service successfully!"); } catch (Exception exp) { Console.WriteLine("Exception: {0}, please make sure you installed EASendMail Service on the server!", exp.Message); } }

See Also

Work with EASendMail Service (Email Queuing)
SendMailToQueue Method
PostToRemoteQueue Method

Online Tutorials

Send Email in MS SQL Server - Tutorial
Send Email with Queue in ASP.NET + C#
Send Bulk Emails with Database Queue in ASP.NET + C#
Send Email with Queue in ASP.NET + VB
Send Bulk Emails with Database Queue in ASP.NET + VB
Send Email with Queue in ASP + VBScript
Send Bulk Emails with Database Queue in ASP + VBScript

Online Examples

C# - Email Queue with EASendMail Service
Visual Basic - Email Queue with EASendMail Service
C++/CLI - Email Queue with EASendMail Service