SmtpSend Method (String, EmailAddressCollection)
Sends the mail message to the specified recipients.

Namespace: MailBee.SmtpMail
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.4 build 677 for .NET 4.5
public bool Send(
	string senderEmail,
	EmailAddressCollection recipients


Type: SystemString
The e-mail address of the sender. If it's a null reference (Nothing in Visual Basic), the e-mail address is taken from From property. If it's an empty string, no sender will be specified (MailBee will issue "MAIL FROM: <>" command to the server).
Type: MailBee.MimeEmailAddressCollection
The list of the message recipients. If it's a null reference (Nothing in Visual Basic), the recipients list is combined from To, Cc, and Bcc lists.

Return Value

Type: Boolean
true if the method succeeds; otherwise, false.
MailBeeExceptionAn error occurred and ThrowExceptions is true.
PlatformNotSupportedExceptionIn .NET Core, multi-threaded sending is supported with async methods only. Use SendAsync(String, EmailAddressCollection) instead.

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 ToIdnAddress for recipients collection 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.

Note Note
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.

Note Note
See OAuth2 topic on how to use the modern OAuth 2.0 authentication (e.g. with Gmail and Office 365).
This sample gets a message from the POP3 server and then sends it to other recipients. From: and To: fields in the original messages are not altered.
// To use the code below, import these namespaces at the top of your code.
using System;
using MailBee;
using MailBee.Pop3Mail;
using MailBee.SmtpMail;
using MailBee.Mime;

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

Smtp mailer = new Smtp();
Pop3 pop = new Pop3();

// Download first message from POP3 inbox.
pop.Login("jdoe", "secret");
mailer.Message = pop.DownloadEntireMessage(1);

// 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 "" instead of "jdoe".
mailer.SmtpServers.Add("", "jdoe", "secret");

// Uncomment next line if ESMTP CHUNKING causes problems with your server (usually, with MS Exchange).
// mailer.SmtpServers[0].SmtpOptions = ExtendedSmtpOptions.NoChunking;

// Specify some recipients to relay the message to.
EmailAddressCollection recipients = new EmailAddressCollection();

// Note: some servers do not allow sending from address different 
// from From: address specified in the message. In this case, adding 
// Resent-From: custom header often helps. However, the message will 
// be altered in this case. Uncomment the next line to add Resent-From: 
// header to the message.

// mailer.Message.Headers["Resent-From"] = mailer.Message.From.Email; 

// Relay the message.
mailer.Send("", recipients);

Console.WriteLine("Sent to: " + mailer.GetAcceptedRecipients().ToString());
See Also