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 SendMail( sFrom As String, _ 
    sTo As String, _ 
    sSubject As String )

    Dim oMail As SmtpMail = New SmtpMail("TryIt")
    Dim oSmtp As SmtpClient = New SmtpClient
 
    Dim errStr As String = ""

    Try
        oMail.From = New MailAddress( sFrom )
        'Please separate multiple addresses by comma(,)
        oMail.To = New AddressCollection(sTo) 
        
        '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", new AddressCollection( txtTo.Text ).ToEncodedString( HeaderEncodingType.EncodingAuto, charset ))
      
        oMail.Subject = sSubject
        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. 
        'oMail.Date = System.DateTime.Now.AddMinutes( 10 )

        oSmtp.SendMailToQueueEx( "myinstance", null, oMail)
        MessageBox.Show( "The message was sent to EASendMail Service successfully!" )

    Catch exp As System.Exception
        errStr = String.Format("Exception: Common: {0}", exp.Message)
        errStr += "Please make sure you installed EASendMail Service on the server!"                
    End Try

    If errStr.Length > 0 Then
        MessageBox.Show(errStr)
    End If
End Sub

[C# - Send Email to Queue]
using System;
using System.Collections;
using EASendMail;

public void SendMail( string sFrom, 
    string sTo, 
    string sSubject )
{
    SmtpMail oMail = new SmtpMail("TryIt");
    SmtpClient oSmtp = new SmtpClient();
    string err = "";

    try
    {
        oMail.From = sFrom;
        //Please separate multiple addresses by comma(,)
        oMail.To = sTo;
        
        //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", new AddressCollection( txtTo.Text ).ToEncodedString( HeaderEncodingType.EncodingAuto, charset ));
    
        oMail.Subject = sSubject;
        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. 
        //oMail.Date = System.DateTime.Now.AddMinutes( 10 );
    
        oSmtp.SendMailToQueueEx( "myinstance", null, oMail  );
        MessageBox.Show( "The message was sent to EASendMail Service successfully!" );

    }
    catch( System.Exception exp )
    {
        err = String.Format( "Exception: Common: {0}", exp.Message );
        err += "Please make sure you installed EASendMail Service on the server!";          
    }   
    
    if( err.Length > 0  )
    {
        MessageBox.Show( err );
    }
}

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