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

Namespace: MailBee.SmtpMail
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 11.2.0 build 590 for .NET 4.5
Syntax
public bool RelayFromEmlFile(
	string filename,
	string senderEmail,
	EmailAddressCollection recipients
)

Parameters

filename
Type: SystemString
The path to the file containing the message source in .EML (RFC2822) format.
senderEmail
Type: SystemString
The e-mail address of the sender.
recipients
Type: MailBee.MimeEmailAddressCollection
The list of the message recipients.

Return Value

Type: Boolean
true if relay succeeded; otherwise, false.
Exceptions
ExceptionCondition
MailBeeExceptionAn error occurred and ThrowExceptions is true.
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(String) method of MailMessage object can be used.

Note Note
If Connect method was not called prior to RelayFromEmlFile(String, String, EmailAddressCollection), 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.
Examples
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
// 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"));
See Also