SmtpClient.PostToRemoteQueue Method


Sends an e-mail message to remote EASendMail Service.

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

Parameters

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.
instance
A String value used to specify EASendMail Service instance.
url
A String value used to specify EASendMail Service Remote Agent URL.
user
A String value used to specify Remote Agent URL user name (optional).
password
A String value used to specify Remote Agent URL password (optional).

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 this method.
Before you use PostToRemoteQueue method, you should deploy EASendMail Service Agent on the remote server.

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.PostToRemoteQueue(oServer, oMail, "", "http://192.168.0.1/eaagent/", "", "")

        ' If you want to use SMTP server setting in EASendMail Service Manager, use
        ' oSmtp.PostToRemoteQueue(Nothing, oMail, "", "http://192.168.0.1/eaagent/", "", "")
        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.PostToRemoteQueue(oServer, oMail, "", "http://192.168.0.1/eaagent/", "", ""); // If you want to use SMTP server setting in EASendMail Service Manager, use // oSmtp.PostToRemoteQueue(null, oMail, "", "http://192.168.0.1/eaagent/", "", ""); 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
SendMailToQueueEx 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