MailBee.NET Objects 4.0

Smtp.MessageRecipientSubmitted Event

Occurs each time the next recipient in the mail message recipients list is accepted or refused by the SMTP server.

public event SmtpMessageRecipientSubmittedEventHandler MessageRecipientSubmitted;

Event Data

The event handler receives an argument of type SmtpMessageRecipientSubmittedEventArgs containing data related to this event. The following SmtpMessageRecipientSubmittedEventArgs properties provide information specific to this event.

Property Description
MailMessage Gets the mail message which is being sent.
RecipientEmail Gets the e-mail address of the recipient of the mail message.
Result Gets the status of submission the recipient e-mail address to the SMTP server.
ServerStatusMessage Gets the string containing the status line of the SMTP server response.
State Gets a reference to the object which was supplied by the developer in state parameter of asynchronous methods of the mailer components.

Remarks

If the message contains multiple recipients, this event is raised for each recipient. The developer can use Result property to detremine whether the recipient was accepted or refused.

Note   If refused recipients are not allowed (AllowRefusedRecipients is false), the component will cancel the SMTP session after raising MessageRecipientSubmitted event.

Example

This sample sends a message in direct send mode to 3 recipients on 2 domains. MessageSenderSubmitted event is raised 3 times (for each recipient).

Note   In some cases, it may be raised more than 2 times. If certain domain has more than one SMTP MX server assigned, and sending to high-priority MX server failed after the message recipient has already been submitted, then backup MX servers are tried (so that the message recipient is submitted again, and so does MessageRecipientSubmitted event).
[C#]
using System;
using MailBee;
using MailBee.SmtpMail;

class Sample
{
    // MessageRecipientSubmitted event handler.
    private static void OnMessageRecipientSubmitted(object sender,
        SmtpMessageRecipientSubmittedEventArgs e)
    {
        if (e.Result)
        {
            Console.WriteLine("SMTP server accepted " + e.RecipientEmail + " address");
        }
        else
        {
            Console.WriteLine("SMTP server refused " + e.RecipientEmail + " address");
        }
    }

    // The actual code.
    static void Main(string[] args)
    {
        Smtp mailer = new Smtp();

        // Get DNS servers from config file/OS settings.
        mailer.DnsServers.Autodetect();

        // Subscribe to the MessageRecipientSubmitted event.
        mailer.MessageRecipientSubmitted +=
            new SmtpMessageRecipientSubmittedEventHandler(OnMessageRecipientSubmitted);

        // Send a message to 3 recipients on 2 domains.
        mailer.To.AsString = "user1@domain1.com, user2@domain1.com, user2@domain2.com";
        mailer.From.Email = "sender@domain.com";
        mailer.Subject = "Test message";
        mailer.Send();

        Console.WriteLine("Message sent to: " + mailer.GetAcceptedRecipients().ToString());
    }
}
[Visual Basic]
Imports System
Imports MailBee
Imports MailBee.SmtpMail

Class Sample
    ' Connected event handler.
    Private Shared Sub OnMessageRecipientSubmitted(ByVal sender As Object, ByVal e As SmtpMessageRecipientSubmittedEventArgs)
        If e.Result Then
            Console.WriteLine("SMTP server accepted " & e.RecipientEmail & " address")
        Else
            Console.WriteLine("SMTP server refused " & e.RecipientEmail & " address")
        End If
    End Sub

    ' The actual code.
    Shared Sub Main(ByVal args As String())
        Dim mailer As New Smtp

        ' Get DNS servers from config file/OS settings.
        mailer.DnsServers.Autodetect()

        ' Subscribe to the MessageRecipientSubmitted event.
        AddHandler mailer.MessageRecipientSubmitted, AddressOf OnMessageRecipientSubmitted

        ' Send a message to 3 recipients on 2 domains.
        mailer.To.AsString = "user1@domain1.com, user2@domain1.com, user2@domain2.com"
        mailer.From.Email = "sender@domain.com"
        mailer.Subject = "Test message"
        mailer.Send()

        Console.WriteLine("Message sent to: " & mailer.GetAcceptedRecipients().ToString())
    End Sub
End Class

See Also

Smtp Class | MailBee.SmtpMail Namespace