Relays (sends without any modifications) the mail message previously saved as an .EML file, to the specified recipients.
true if relay succeeded; otherwise, false.
This method reads the message raw data from a file and then sends the message intact. Sender and recipients specified in the message itself (such as From: and To: fields) are ignored.
To save a message into an .EML file, SaveMessage method of MailMessage object can be used.
Note If Connect method was not called prior to RelayFromEmlFile, MailBee will call it automatically, or send the message in direct send mode (through DNS MX lookup) if no SMTP relay server is specified in SmtpServers collection or its Priority is lower than top priority of DNS servers available in DnsServers collection.
| Exception Type | Condition |
|---|---|
| MailBeeException | An error occurred and ThrowExceptions is true. |
This sample relays the mail message from .EML file to 3 recipients by submitting the message to the SMTP relay server. MessageRecipientSubmitted event is used to report which recipients have been accepted or refused.
[C#] using System; using MailBee; using MailBee.SmtpMail; using MailBee.Mime; class Sample { // MessageRecipientSubmitted event handler. private static void OnMessageRecipientSubmitted(object sender, SmtpMessageRecipientSubmittedEventArgs e) { if (e.Result) { Console.WriteLine(e.RecipientEmail + " accepted by the server"); } else { Console.WriteLine(e.RecipientEmail + " rejected by the server"); } } // The actual code. static void Main(string[] args) { Smtp mailer = new Smtp(); // Specify SMTP server to use, and enable SMTP authentication. SmtpServer server = new SmtpServer("smtp-relay.host.com", "jdoe", "secret"); mailer.SmtpServers.Add(server); // Subscribe to the MessageRecipientSubmitted event. mailer.MessageRecipientSubmitted += new SmtpMessageRecipientSubmittedEventHandler(OnMessageRecipientSubmitted); // Send the message from the file to 3 recipients. mailer.RelayFromEmlFile(@"C:\Temp\message.eml", "jdoe@host.com", "client@company.com, b.smith@domain1.com, j.smith@domain2.com"); } }
[Visual Basic] Imports System Imports MailBee Imports MailBee.SmtpMail Imports MailBee.Mime Class Sample ' MessageRecipientSubmitted event handler. Private Shared Sub OnMessageRecipientSubmitted(ByVal sender As Object, _ ByVal e As SmtpMessageRecipientSubmittedEventArgs) If (e.Result) Then Console.WriteLine(e.RecipientEmail + " accepted by the server") Else Console.WriteLine(e.RecipientEmail + " rejected by the server") End If End Sub ' The actual code. Shared Sub Main(ByVal args As String()) Dim mailer As New Smtp ' Specify SMTP server to use, and enable SMTP authentication. Dim server As New SmtpServer("smtp-relay.host.com", "jdoe", "secret") mailer.SmtpServers.Add(server) ' Subscribe to the MessageRecipientSubmitted event. AddHandler mailer.MessageRecipientSubmitted, AddressOf OnMessageRecipientSubmitted ' Send the message from the file to 3 recipients. mailer.RelayFromEmlFile("C:\Temp\message.eml", "jdoe@host.com", _ "client@company.com, b.smith@domain1.com, j.smith@domain2.com") End Sub End Class
Smtp Class | MailBee.SmtpMail Namespace | Smtp.RelayFromEmlFile Overload List