SmtpBeginSend Method

Note: This API is now obsolete.

Begins an asynchronous request for sending a mail message to recipients.

Namespace: MailBee.SmtpMail
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.4 build 677 for .NET 4.5
Syntax
[ObsoleteAttribute("This method is obsolete in .NET 4.5+. Use SendAsync instead.")]
public IAsyncResult BeginSend(
	string senderEmail,
	EmailAddressCollection recipients,
	AsyncCallback callback,
	Object state
)

Parameters

senderEmail
Type: SystemString
The e-mail address of the sender.
recipients
Type: MailBee.MimeEmailAddressCollection
The list of the message recipients.
callback
Type: SystemAsyncCallback
The AsyncCallback delegate. You can leave it a null reference (Nothing in Visual Basic) if you do not use callbacks.
state
Type: SystemObject
An object that contains state information for this request. You can leave it a null reference (Nothing in Visual Basic).

Return Value

Type: IAsyncResult
An IAsyncResult that references the asynchronous sending the message.
Exceptions
ExceptionCondition
MailBeeInvalidStateExceptionThere is already an operation in progress.
Remarks
Examples
This WinForms sample sends a mail message asynchronously. The callback function is used to receive notification on asynchronous method completion. Events are used to track send mail progress.
// To use the code below, import MailBee namespaces at the top of your code.
using MailBee;
using MailBee.SmtpMail;
using MailBee.DnsMX;
using MailBee.Mime;

// Put the code below inside your class.

// MessageSubmittedToServer event handler.
private void OnMessageSubmittedToServer(object sender,
    SmtpMessageSubmittedToServerEventArgs e)
{
    // If no recipients received the message, this event won't be raised.
    // It's safe to assume AcceptedRecipients collection is not empty.
    string domain = e.AcceptedRecipients[0].GetDomain();
    MessageBox.Show("Message was sent to recipients at " + domain + " domain");
}

// MessageRecipientSubmitted event handler.
private void OnMessageRecipientSubmitted(object sender,
    SmtpMessageRecipientSubmittedEventArgs e)
{
    // If a particular recipient was refused, let the user know.
    if (!e.Result)
    {
        MessageBox.Show("For e-mail address " + e.RecipientEmail +
            ", server responded: " + e.ServerStatusMessage);
    }
}

// Send callback function.
private void SendCallback(IAsyncResult result)
{
    Smtp mailer = (Smtp)result.AsyncState;
    mailer.EndSend();
    MessageBox.Show("The e-mail was sent to: " +
        mailer.GetAcceptedRecipients().ToString());
}

// The actual code.
private void Form1_Load(object sender, System.EventArgs e)
{
    Smtp mailer = new Smtp();

    // Enable logging SMTP session into a file.
    mailer.Log.Enabled = true;
    mailer.Log.Filename = @"C:\Temp\log.txt";
    mailer.Log.Clear();
    mailer.Log.Format = LogFormatOptions.AddContextInfo;

    // Get the list of DNS servers for MX lookup from OS settings 
    // (app.config/web.config/machine.config files are ignored).
    mailer.DnsServers.Autodetect(
        DnsAutodetectOptions.Registry | DnsAutodetectOptions.Wmi);

    // Subscribe to events.
    mailer.MessageSubmittedToServer +=
        new SmtpMessageSubmittedToServerEventHandler(OnMessageSubmittedToServer);
    mailer.MessageRecipientSubmitted +=
        new SmtpMessageRecipientSubmittedEventHandler(OnMessageRecipientSubmitted);

    mailer.From.Email = "jdoe@domain.com";
    mailer.Subject = "Important details";

    // Demonstrate different methods of adding To, CC, and BCC recipients. 
    mailer.To.AsString = "kathy@domain.com, \"Bill Smith, Jr.\" <b.smith@company.com>";
    mailer.Cc.Add("Peter", "peter@domain.com");
    mailer.Cc.Add("john@domain.com");
    mailer.Bcc.AsString = "echelon@secret.com";

    // Specify HTML body.
    mailer.BodyHtmlText = "<html>Here are the details.</html>";

    // Create plain-text version.
    mailer.Message.MakePlainBodyFromHtmlBody();

    // Initiate an asynchronous send mail attempt.
    mailer.BeginSend(null, null, new AsyncCallback(SendCallback), mailer);
}
See Also