MailBee.NET Objects 3.1

Smtp.MessageSubmittedToServer Event

Occurs each time the message is successfully submitted to the SMTP server.

public event SmtpMessageSubmittedToServerEventHandler MessageSubmittedToServer;

Event Data

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

Property Description
AcceptedRecipients Gets the list of all recipients which were accepted by the SMTP server.
ActualSenderEmail Gets the e-mail address of the sender of the mail message.
IntendedRecipients Gets the list of recipients the message is addressed to.
MailMessage Gets the mail message which was successfully submitted to the SMTP server.
RefusedRecipients Gets the list of all recipients which were refused by the SMTP server.
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 sent to multiple SMTP servers (common case in direct send mode where the message is submitted to SMTP MX server of each recipient domain separately), this event is raised for each SMTP server the message was successfully submitted to.

Example

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

[C#]
using System;
using MailBee;
using MailBee.SmtpMail;

class Sample
{
    // MessageSubmittedToServer event handler.
    private static void OnMessageSubmittedToServer(object sender,
        SmtpMessageSubmittedToServerEventArgs e)
    {
        Console.WriteLine(e.AcceptedRecipients.ToString() + " accepted");
    }

    // 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.MessageSubmittedToServer +=
            new SmtpMessageSubmittedToServerEventHandler(OnMessageSubmittedToServer);

        // 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();
    }
}
[Visual Basic]
Imports System
Imports MailBee
Imports MailBee.SmtpMail

Class Sample
    ' MessageSubmittedToServer event handler.
    Private Shared Sub OnMessageSubmittedToServer(ByVal sender As Object, _
        ByVal e As SmtpMessageSubmittedToServerEventArgs)
        Console.WriteLine(e.AcceptedRecipients.ToString() & " accepted")
    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.MessageSubmittedToServer, AddressOf OnMessageSubmittedToServer

        ' 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()
    End Sub
End Class

See Also

Smtp Class | MailBee.SmtpMail Namespace