SmtpRelayFromEmlFile Method (String, String, String) |
Namespace: MailBee.SmtpMail
Exception | Condition |
---|---|
MailBeeException | An error occurred and ThrowExceptions is true. |
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 |
---|
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. |
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"); } }