Occurs when the smtp server rejected a recipient.
[Visual Basic]
Public Event OnRcptToError As OnRcptToErrorEventHandler
Public Delegate Sub OnRcptToErrorEventHandler( _
ByVal sender As Object, _
ByVal errorStr As String, _
ByVal rcpt As String, _
ByRef sendnext As Boolean, _
ByRef cancel As Boolean _
)
[C#]
public event OnRcptToErrorEventHandler OnRcptToError;
public delegate void OnRcptToErrorEventHandler(
object sender,
string error,
string rcpt,
ref bool sendnext,
ref bool cancel
);
[C++]
public: __event OnRcptToErrorEventHandler* OnRcptToError;
public __gc __delegate void OnRcptToErrorEventHandler(
Object* sender,
String* error,
String* rcpt,
bool __gc *sendnext,
bool __gc *cancel
);
Event Data
Remarks
Example
[Visual Basic, C#, C++, JScript.NET] To get the full samples of EASendMail, please refer to Samples section.
[Visual Basic]
Imports System.Windows.Forms
Imports EASendMail
Module Module1
Sub OnRcptToError( _
ByVal sender As Object, _
ByVal errorstr As String, _
ByVal rcpt As String, _
ByRef sendnext As Boolean, _
ByRef cancel As Boolean _
)
If MessageBox.Show(String.Format("{0} is rejected by server: {1}, are you want to continue to send the email?", _
rcpt, errorstr), "Warning", MessageBoxButtons.OKCancel) = DialogResult.OK Then
sendnext = True
End If
End Sub
Sub Main()
SendMail()
End Sub
Sub SendMail()
Dim oMail As SmtpMail = New SmtpMail("TryIt")
Dim oSmtp As SmtpClient = New SmtpClient
Try
Dim oServer As SmtpServer = New SmtpServer("myserveraddress")
oMail.From = New MailAddress("from@adminsystem.com")
oMail.To.Add(New MailAddress("good@adminsystem.com"))
oMail.To.Add(New MailAddress("bad@adminsystem.com))
oMail.Subject = "test subject"
oMail.TextBody = "test body"
AddHandler oSmtp.OnRcptToError, AddressOf OnRcptToError
oSmtp.SendMail(oServer, oMail)
Console.WriteLine("Message was sent")
Catch exp As SmtpTerminatedException
Console.WriteLine(exp.Message)
Catch exp As SmtpServerException
Console.WriteLine("Exception: Server Respond: {0}", exp.ErrorMessage)
Catch exp As System.Net.Sockets.SocketException
Console.WriteLine("Exception: Networking Error: {0} {1}", exp.ErrorCode, exp.Message)
Catch exp As System.ComponentModel.Win32Exception
Console.WriteLine("Exception: System Error: {0} {1}", exp.ErrorCode, exp.Message)
Catch exp As System.Exception
Console.WriteLine("Exception: Common: {0}", exp.Message)
End Try
End Sub
End Module
[C#]
using System;
using System.Windows.Forms;
using EASendMail;
namespace Test
{
class Class1
{
public static void OnRcptToError(
object sender,
string error,
string rcpt,
ref bool sendnext,
ref bool cancel
)
{
if( MessageBox.Show(String.Format("{0} is rejected by server: {1}, are you want to continue to send the email?",
rcpt, error), "Warning", MessageBoxButtons.OKCancel) == DialogResult.OK )
{
sendnext = true;
}
}
[STAThread]
static void Main(string[] args)
{
SendMail();
}
static void SendMail()
{
SmtpMail oMail = new SmtpMail("TryIt");
SmtpClient oSmtp = new SmtpClient();
try
{
SmtpServer oServer = new SmtpServer("myserveraddress");
oMail.From = new MailAddress("from@adminsystem.com" );
oMail.To.Add( new MailAddress("good@adminsystem.com" ));
oMail.To.Add( new MailAddress("bad@adminsystem.com" ));
oMail.Subject = "test subject";
oMail.TextBody = "test body";
oSmtp.OnRcptToError += new SmtpClient.OnRcptToErrorEventHandler( OnRcptToError );
oSmtp.SendMail( oServer, oMail );
Console.WriteLine( "Message was sent" );
}
catch( SmtpTerminatedException exp )
{
Console.WriteLine( exp.Message );
}
catch( SmtpServerException exp )
{
Console.WriteLine( "Exception: Server Respond: {0}", exp.ErrorMessage );
}
catch( System.Net.Sockets.SocketException exp )
{
Console.WriteLine( "Exception: Networking Error: {0} {1}", exp.ErrorCode, exp.Message );
}
catch( System.ComponentModel.Win32Exception exp )
{
Console.WriteLine( "Exception: System Error: {0} {1}", exp.ErrorCode, exp.Message );
}
catch( System.Exception exp )
{
Console.WriteLine( "Exception: Common: {0}", exp.Message );
}
}
}
}
[C++]
#include "stdafx.h"
#using <mscorlib.dll>
using namespace System;
using namespace System::Windows::Forms;
using namespace EASendMail;
public __gc class SmtpClientEventHandler
{
public:
static void OnRcptToError(
Object* sender,
String* error,
String* rcpt,
bool __gc *sendnext,
bool __gc *cancel
)
{
if( MessageBox::Show(String::Format("{0} is rejected by server: {1}, are you want to continue to send the email?",
rcpt, error), "Warning", MessageBoxButtons::OKCancel) == DialogResult::OK )
{
*sendnext = true;
}
}
};
void SendMail()
{
SmtpMail *oMail = new SmtpMail(S"TryIt");
SmtpClient *oSmtp = new SmtpClient();
try
{
SmtpServer *oServer = new SmtpServer(S"myserveraddress");
oMail->From = new MailAddress(S"from@adminsystem.com" );
oMail->To->Add( new MailAddress(S"good@adminsystem.com" ));
oMail->To->Add( new MailAddress(S"bad@adminsystem.com" ));
oMail->Subject = "test subject";
oMail->TextBody = "test body";
oSmtp->OnRcptToError += new SmtpClient::OnRcptToErrorEventHandler( NULL, SmtpClientEventHandler::OnRcptToError );
oSmtp->SendMail( oServer, oMail );
Console::WriteLine( S"message was sent" );
}
catch( EASendMail::SmtpTerminatedException *exp )
{
Console::WriteLine( exp->Message );
}
catch( EASendMail::SmtpServerException *exp )
{
Console::WriteLine( S"Exception: Server Respond: {0}", exp->ErrorMessage );
}
catch( System::Net::Sockets::SocketException *exp )
{
Console::WriteLine( S"Exception: Networking Error: {0} {1}", exp->ErrorCode.ToString(S"d"), exp->Message );
}
catch( System::ComponentModel::Win32Exception *exp )
{
Console::WriteLine( S"Exception: System Error: {0} {1}", exp->ErrorCode.ToString(S"d"), exp->Message );
}
catch( System::Exception *exp )
{
Console::WriteLine( S"Exception: Common: {0}", exp->Message );
}
}
int _tmain()
{
SendMail();
return 0;
}