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, Boolean % sendnext, Boolean % cancel );
Event Data
Remarks
Example
[Visual Basic, C#, C++, JScript.NET] To get the full samples of EASendMail, please refer to Samples section.
[VB - Send Email with OnRcptToError Event] 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 SendMail() Try Dim oServer As SmtpServer = New SmtpServer("myserveraddress") Dim oMail As SmtpMail = New SmtpMail("TryIt") 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" Dim oSmtp As SmtpClient = New SmtpClient() AddHandler oSmtp.OnRcptToError, AddressOf OnRcptToError oSmtp.SendMail(oServer, oMail) Console.WriteLine("Message was sent") Catch exp As Exception Console.WriteLine("Exception: {0}", exp.Message) End Try End Sub Sub Main() SendMail() End Sub End Module
[C# - Send Email with OnRcptToError Event] 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; } } static void SendMail() { try { SmtpServer oServer = new SmtpServer("myserveraddress"); SmtpMail oMail = new SmtpMail("TryIt"); 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"; SmtpClient oSmtp = new SmtpClient(); oSmtp.OnRcptToError += new SmtpClient.OnRcptToErrorEventHandler(OnRcptToError); oSmtp.SendMail( oServer, oMail ); Console.WriteLine( "Message was sent" ); } catch(Exception exp) { Console.WriteLine("Exception: {0}", exp.Message); } } [STAThread] static void Main(string[] args) { SendMail(); } } }
[C++/CLI - Send Email with OnRcptToError Event] using namespace System; using namespace System::Windows::Forms; using namespace EASendMail; static void OnRcptToError( Object^ sender, String^ error, String^ rcpt, Boolean % sendnext, Boolean % 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; } } static void SendMail() { try { SmtpServer ^oServer = gcnew SmtpServer("myserveraddres"); SmtpMail ^oMail = gcnew SmtpMail("TryIt"); oMail->From = gcnew MailAddress("from@adminsystem.com"); oMail->To->Add(gcnew MailAddress("good@adminsystem.com")); oMail->To->Add(gcnew MailAddress("bad@adminsystem.com")); oMail->Subject = "test subject"; oMail->TextBody = "test body"; SmtpClient ^oSmtp = gcnew SmtpClient(); oSmtp->OnRcptToError += gcnew SmtpClient::OnRcptToErrorEventHandler(&OnRcptToError); oSmtp->SendMail(oServer, oMail); Console::WriteLine("message was sent"); } catch(System::Exception ^exp) { Console::WriteLine("Exception: {0}", exp->Message); } } int main(array<String ^> ^args) { SendMail(); return 0; }
See Also
SmtpClient.SendMail Method
SmtpClient.BeginSendMail Method
Online Tutorials
Send Email with Event Handler in C# - Tutorial
Send Email with Event Handler in VB - Tutorial
Send Email with Event Handler in Managed C++/CLI - Tutorial