MailBee.NET Objects 3.1

Smtp.BeginRelayFromEmlFile Method 

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

public IAsyncResult BeginRelayFromEmlFile(
   string filename,
   string senderEmail,
   EmailAddressCollection recipients,
   AsyncCallback callback,
   object state
);

Parameters

filename
The path to the file containing the message source in .EML (RFC2822) format.
senderEmail
The e-mail address of the sender.
recipients
The list of the message recipients.
callback
The AsyncCallback delegate. You can leave it a null reference (Nothing in Visual Basic) if you do not use callbacks.
state
An object that contains state information for this request. You can leave it a null reference (Nothing in Visual Basic).

Return Value

An IAsyncResult that references the asynchronous relaying the message.

Remarks

This method is an asynchronous version of RelayFromEmlFile.

Exceptions

Exception Type Condition
MailBeeInvalidStateException There is already an operation in progress.

Example

This console sample demonstrates asynchronous relaying the mail message using direct send approach (via DNS MX lookup). No callback function is used.

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

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

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

        // Initiate an asynchronous relay.
        mailer.BeginRelayFromEmlFile(@"C:\Temp\message.eml", "kathy@company.com",
            new EmailAddressCollection("mike@domain1.com, bob@domain2.com"), null, null);

        // Simulate some lengthy work here. At the same time, 
        // the message is being sent to recipients domains on another thread.
        System.Threading.Thread.Sleep(3000);

        // End the relay request. If send mail operation is still in progress, 
        // the method will wait until it's finished.
        mailer.EndRelayFromEmlFile();

        // Print the outcome.
        Console.WriteLine("Successfully sent to: " + mailer.GetAcceptedRecipients().ToString());
        Console.WriteLine("Not sent to: " + mailer.GetRefusedRecipients().ToString());
    }
}
[Visual Basic]
Imports System
Imports MailBee
Imports MailBee.SmtpMail
Imports MailBee.Mime

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

        ' Get the list of DNS servers from OS settings or the config file.
        mailer.DnsServers.Autodetect()

        ' Initiate an asynchronous relay.
        mailer.BeginRelayFromEmlFile("C:\Temp\message.eml", "kathy@company.com", _
            New EmailAddressCollection("mike@domain1.com, bob@domain2.com"), Nothing, Nothing)

        ' Simulate some lengthy work here. At the same time, 
        ' the message is being sent to recipients domains on another thread.
        System.Threading.Thread.Sleep(3000)

        ' End the relay request. If send mail operation is still in progress, 
        ' the method will wait until it's finished.
        mailer.EndRelayFromEmlFile()

        ' Print the outcome.
        Console.WriteLine("Successfully sent to: " & mailer.GetAcceptedRecipients().ToString())
        Console.WriteLine("Not sent to: " & mailer.GetRefusedRecipients().ToString())
    End Sub
End Class

See Also

Smtp Class | MailBee.SmtpMail Namespace | RelayFromEmlFile