MailBee.NET Objects 7.2

Smtp.MessageSenderSubmitted Event

Occurs after the sender of the mail message was successfully submitted to the SMTP server.

public event SmtpMessageSenderSubmittedEventHandler MessageSenderSubmitted;

Event Data

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

Property Description
MailMessage Gets the mail message which is being sent.
SenderEmail Gets the e-mail address of the sender of the mail message.
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 is being sent to multiple SMTP servers (such as to SMTP MX servers in direct mode), this event will be raised multiple times (once per each individual SMTP connection).

Example

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

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 sender has already been submitted, then backup MX servers are tried (so that the message sender is submitted again, and so does MessageSenderSubmitted event).
[C#]
using System;
using MailBee;
using MailBee.SmtpMail;

class Sample
{
    // MessageSenderSubmitted event handler.
    private static void OnMessageSenderSubmitted(object sender,
        SmtpMessageSenderSubmittedEventArgs e)
    {
        Console.WriteLine("SMTP server accepted " + e.SenderEmail + " 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 MessageSenderSubmitted event.
        mailer.MessageSenderSubmitted +=
            new SmtpMessageSenderSubmittedEventHandler(OnMessageSenderSubmitted);

        // 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 OnMessageSenderSubmitted(ByVal sender As Object, ByVal e As SmtpMessageSenderSubmittedEventArgs)
        Console.WriteLine("SMTP server accepted " & e.SenderEmail & " address")
    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 MessageSenderSubmitted event.
        AddHandler mailer.MessageSenderSubmitted, AddressOf OnMessageSenderSubmitted

        ' 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