MailBee.NET Objects 4.0

Smtp.RelayFromEmlFile Method (String, String, EmailAddressCollection)

Relays (sends without any modifications) the mail message previously saved as an .EML file, to the specified recipients.

public bool RelayFromEmlFile(
   string filename,
   string senderEmail,
   EmailAddressCollection recipients
);

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.

Return Value

true if relay succeeded; otherwise, false.

Remarks

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.

Exceptions

Exception TypeCondition
MailBeeExceptionAn error occurred and ThrowExceptions is true.

Example

This sample relays the mail message from .EML file to the recipients, using the following configuration (which targets high reliability of send mail operation):

  1. Attempt to send to SMTP relay server at smtp1.domain.com first
  2. If this fails, try to send to backup SMTP relay server at smtp2.domain.com
  3. If this fails too, try direct send mode. To discover SMTP servers accepting mails for recipients domains (i.e. to perform DNS MX lookup), use DNS servers specified by the operating system
  4. If the DNS servers reported by OS are not available or down, use backup DNS server at 10.20.30.40
[C#]
// To use the code below, import MailBee namespaces at the top of your code.
using MailBee;
using MailBee.SmtpMail;
using MailBee.Mime;

// The actual code (put it into a method of your class)

Smtp mailer = new Smtp();

mailer.SmtpServers.Add("smtp1.domain.com", 25, 0);    // top priority.
mailer.SmtpServers.Add("smtp2.domain.com", 25, 1);    // low priority.

// Auto-detect DNS servers from OS settings or config file.
mailer.DnsServers.Autodetect();

// Add backup DNS server of low priority (priority of DNS servers 
// registered in OS is usually in the range 0 to 10).
mailer.DnsServers.Add("10.20.30.40", 100);

// Send the message from the file.
mailer.RelayFromEmlFile(@"C:\Temp\message.eml", "from@domain.com",
    new EmailAddressCollection("to@company.com"));
[Visual Basic]
' To use the code below, import MailBee namespaces at the top of your code.
Imports MailBee
Imports MailBee.SmtpMail
Imports MailBee.Mime

' The actual code (put it into a method of your class)

Dim mailer As New Smtp

mailer.SmtpServers.Add("smtp1.domain.com", 25, 0)    ' top priority.
mailer.SmtpServers.Add("smtp2.domain.com", 25, 1)    ' low priority.

' Auto-detect DNS servers from OS settings or config file.
mailer.DnsServers.Autodetect()

' Add backup DNS server of low priority (priority of DNS servers 
' registered in OS is usually in the range 0 to 10).
mailer.DnsServers.Add("10.20.30.40", 100)

' Send the message from the file.
mailer.RelayFromEmlFile("C:\Temp\message.eml", "from@domain.com", _
    New EmailAddressCollection("to@company.com"))

See Also

Smtp Class | MailBee.SmtpMail Namespace | Smtp.RelayFromEmlFile Overload List