Occurs when an email was sent by BatchSendMail method.
[VisualĀ Basic]
Public Event OnBatchSendMail As OnBatchSendMailEventHandler
Public Delegate Sub OnBatchSendMailEventHandler( _
ByVal sender As Object, _
ByVal server As SmtpServer, _
ByVal mail As SmtpMail, _
ByVal ep As Exception, _
ByRef cancel As Boolean _
)
[C#]
public event OnBatchSendMailEventHandler OnBatchSendMail;
public delegate void OnBatchSendMailEventHandler(
object sender,
SmtpServer server,
SmtpMail mail,
Exception ep,
ref bool cancel
);
[C++]
public: __event OnBatchSendMailEventHandler* OnBatchSendMail;
public __gc __delegate void OnBatchSendMailEventHandler(
Object* sender,
SmtpServer *server,
SmtpMail *mail,
Exception *ep,
bool __gc *cancel
);
Event Data
Remarks
Example
[Visual Basic, C#] To get the full samples of EASendMail, please refer to Samples section.
[Visual Basic]
Imports EASendMail
Public Shared Sub OnBatchSendMail( _
sender As Object, _
server As SmtpServer, _
mail As SmtpMail, _
ep As Exception, _
ByRef cancel As Boolean )
' you can insert the result to database in this subroutine.
If Not ( ep Is NOthing ) Then
'something wrong, please refer to ep.Message
'cancel = True ' set cancel to true can cancel the remained emails.
Else
'delivered
End If
End Sub
Public SendMail( _
fromAddr As String, _
rcpts As String, _
server As String )
Dim oAddrs As New AddressCollection(rcpts)
Dim count As Integer = oAddrs.Count
' the maximum thread count to send email. you can increase or decrease this value.
Dim maxThreads As Integer = 5
Dim mails(count-1) As SmtpMail
Dim servers(count-1) As SmtpServer
For i As Integer = 0 To count - 1
Dim oMail As SmtpMail = New SmtpMail("TryIt")
oMail.From = New MailAddress( fromAddr )
oMail.Subject = "test subject"
oMail.To.Add( oAddrs(i))
oMail.TextBody = String.Format( "test body to {0}", oAddrs(i).ToString())
mails(i) = oMail
Next
Dim oServer As SmtpServer = New SmtpServer( server )
servers(0) = oServer
Dim oSmtp As SmtpClient = New SmtpClient()
Try
' oSmtp.LogFileName = "c:\smtp.log"
' if the log wasn't able to be generated,
' please create a smtp.log file on C: and assign everyone read-write permission to this
' file, then try it again.
' if you want to catch the result in OnBatchSendMail, please add the following code:
AddHandler oSmtp.OnBatchSendMail, AddressOf OnBatchSendMail
oSmtp.BatchSendMail( maxThreads, servers, mails )
Response.Write( "EASendMail will send emails in background!" )
Catch exp As System.Exception
Response.Write( String.Format("Exception: Common: {0}", exp.Message))
End Try
End Sub
[C#]
using System;
using EASendMail;
public static void OnBatchSendMail(
object sender,
SmtpServer server,
SmtpMail mail,
Exception ep, ref bool cancel )
{
// you can insert the result to database in this subroutine.
if( ep != null )
{
// something wrong, please refer to ep.Message
//cancel = true; // set cancel to true can cancel the remained emails.
}
else
{
//delivered
}
}
public void SendMail(
string fromAddr,
string rcpts,
string server )
{
AddressCollection oAddrs = new AddressCollection(rcpts);
int count = oAddrs.Count;
// the maximum thread count to send email. you can increase or decrease this value.
int maxThreads = 5;
SmtpMail [] mails = new SmtpMail[count];
SmtpServer[] servers = new SmtpServer[1];
for( int i = 0; i < count; i++ )
{
SmtpMail oMail = new SmtpMail("TryIt");
oMail.From = fromAddr;
oMail.Subject = "test subject";
oMail.To.Add( oAddrs[i] );
oMail.TextBody = String.Format( "test body to {0}", oAddrs[i].ToString());
mails[i] = oMail;
}
SmtpServer oServer = new SmtpServer(txtServer.Text);
servers[0] = oServer;
SmtpClient oSmtp = new SmtpClient();
try
{
// oSmtp.LogFileName = "c:\\smtp.log";
// if the log wasn't able to be generated,
// please create a smtp.log file on C: and assign everyone read-write permission to this
// file, then try it again.
// if you want to catch the result in OnBatchSendMail event, please add the following code
oSmtp.OnBatchSendMail += new EASendMail.SmtpClient.OnBatchSendMailEventHandler( OnBatchSendMail );
oSmtp.BatchSendMail( maxThreads, servers, mails );
Response.Write( "EASendMail will send message in background!" );
}
catch( System.Exception exp )
{
Response.Write( String.Format( "Exception: Common: {0}", exp.Message ));
}
}