|SmtpSend Method (String, String)|
public bool Send( string senderEmail, string recipientEmails )
Public Function Send ( senderEmail As String, recipientEmails As String ) As Boolean
|MailBeeException||An error occurred and ThrowExceptions is true.|
|PlatformNotSupportedException||In .NET Core, multi-threaded sending is supported with async methods only. Use SendAsync(String, String) instead.|
QuickSend(MailMessage) method can be used to send a mail message with a single line of code.
SendMailMerge(String, EmailAddressCollection, DataTable) or SendJobs methods perform sending of large volumes of e-mails including mail merge over database.
You can improve performance of sending large messages by increasing TcpBufSize value.
To specify international e-mail addresses (IDN domains), call EscapeIdnDomain(String) for senderEmail string and for each individual value in recipientEmails to convert e-mail addresses from human-readable into SMTP-safe format.
Message property represents the mail message to be sent.
Log object can be used to enable logging SMTP session into a file or memory buffer.
Delivery status notifications can be enabled and configured by setting DeliveryNotification properties.
UploadMessage(MailMessage, String, SystemMessageFlags) method can be used to upload the sent message into IMAP4 folder such as "Sent items".
The operation progress can be monitored through subscribing to Smtp class events or by deriving a new class from Smtp and overriding OnEventName methods.
If Connect method was previously called and the connection with the SMTP relay server was established, Send method will send the message to this server.
If Connect method was not called, Send method will automatically connect to the server specified in SmtpServers collection, send the message, and then disconnect.
If SmtpServers collection contains more than one server, Connect method will try to send the message to the top priority server (see Priority). If it fails, other servers will be tried accordingly their priority values.
If SmtpServers collection is empty or the priority of the most preferred SMTP relay server in SmtpServers collection is less than than the priority of the most preferred DNS server in DnsServers collection, the message will be sent in direct send mode. In this mode, MailBee performs DNS MX lookup for all recipients domains to discover which hosts accept mail for these domains (such hosts are called SMTP MX servers), and then sends the message directly to these servers. In other words, MailBee itself will act as a relay SMTP server. However, it's recommended sending host have assigned DNS MX or A record. Systems which actively send mail but don't have any DNS records assigned are typically used by spammers, thus many SMTP MX servers will not accept mail from such host and may even blacklist its IP address.
If both SmtpServers and DnsServers collections are non-empty, the collection having higher priority server will be tried first (if top priority servers of both collections have the same priority, SmtpServers is preferred). If sending to some or all recipients fails due to failure of some servers, another collection will be used to send the message to the failed recipients. Thus, sending to both SMTP relay servers and servers discovered via DNS MX lookup can be performed in a single Send method call, providing high level of reliability of send mail operation.
|SMTP and DNS server priority values are zero-based. 0 is the highest priority while 999 is the lowest priority.|
In direct send mode, it's possible to send the message to all SMTP MX servers simultaneously. This may greatly improve performance when sending to multiple recipients. The developer can enable multi-threading by setting MaxThreadCount property value to -1 (unlimited number of thread) or to the maximum number of threads the application is allowed to use.
// To use the code below, import these namespaces at the top of your code. using System; using MailBee; using MailBee.SmtpMail; using MailBee.Mime; // The actual code (put it into a method of your class) Smtp mailer = new Smtp(); // Specify SMTP server to use, and enable SMTP authentication. Remove // last 2 parameters if authentication is not required by your server. // If your server requires authentication and expects e-mail address to // be specified as login name, use "email@example.com" instead of "bounce". mailer.SmtpServers.Add("smtp.domain.com", "bounce", "password"); // Uncomment next line if ESMTP CHUNKING causes problems with your server (usually, with MS Exchange). // mailer.SmtpServers.SmtpOptions = ExtendedSmtpOptions.NoChunking; // Specify From: field. mailer.From.AsString = "John Doe <firstname.lastname@example.org>"; // Set recipients mailer.To.AsString = "Bill Smith <email@example.com>;, firstname.lastname@example.org"; mailer.Subject = "Report"; mailer.BodyPlainText = "This is the report."; // Send from email@example.com rather than firstname.lastname@example.org. // email@example.com will appear in Return-Path header. // We set recipientEmails=null to send to addresses specified in the message. mailer.Send("firstname.lastname@example.org", (string)null); Console.WriteLine("Sent to: " + mailer.GetAcceptedRecipients().ToString());
' 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 ' Specify SMTP server to use, and enable SMTP authentication. Remove ' last 2 parameters if authentication is not required by your server. ' If your server requires authentication and expects e-mail address to ' be specified as login name, use "email@example.com" instead of "bounce". mailer.SmtpServers.Add("smtp.domain.com", "bounce", "password") ' Uncomment next line if ESMTP CHUNKING causes problems with your server (usually, with MS Exchange). ' mailer.SmtpServers(0).SmtpOptions = ExtendedSmtpOptions.NoChunking ' Specify From: field mailer.From.AsString = "John Doe <firstname.lastname@example.org>" ' Set recipients. mailer.To.AsString = "Bill Smith <email@example.com>;, firstname.lastname@example.org" mailer.Subject = "Report" mailer.BodyPlainText = "This is the report." ' Send from email@example.com rather than firstname.lastname@example.org. ' email@example.com will appear in Return-Path header. ' We set recipientEmails=null to send to addresses specified in the message. mailer.Send("firstname.lastname@example.org", CStr(Nothing)) Console.WriteLine("Sent to: " & mailer.GetAcceptedRecipients().ToString())