Smtp Class
Provides properties and methods for sending messages using the SMTP protocol.
Inheritance Hierarchy
SystemObject
  MailBee.SmtpMailSmtp

Namespace: MailBee.SmtpMail
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.4 build 677 for .NET 4.5
Syntax
public class Smtp : IComponent, IDisposable

The Smtp type exposes the following members.

Constructors
  NameDescription
Public methodSmtp
Creates an instance of Smtp class.
Public methodSmtp(String)
Creates and unlocks an instance of Smtp class.
Top
Methods
  NameDescription
Public methodAbort
Forces MailBee to cancel all pending operations and close all opened connections as soon as possible.
Public methodCode exampleAddAttachment
Reads the specified file from disk and adds it as attachment to the message.
Public methodAddAttachmentAsync
async/await version of AddAttachment(String).
Public methodCode exampleAddJob(String, String, EmailAddressCollection)
Puts an e-mail message onto waiting list for subsequent processing in bulk mode.
Public methodCode exampleAddJob(String, MailMessage, String, EmailAddressCollection)
Puts the specified e-mail message onto waiting list for subsequent processing in bulk mode.
Public methodCode exampleAddJob(String, String, EmailAddressCollection, DataTable)
Puts a "mail merge over database" job onto waiting list for subsequent processing in bulk mode.
Public methodCode exampleAddJob(String, String, EmailAddressCollection, IDataReader)
Puts a "mail merge over database" job onto waiting list for subsequent processing in bulk mode.
Public methodCode exampleAddJob(String, String, Boolean, String, EmailAddressCollection)
Puts the e-mail message stored in an .EML file onto waiting list for subsequent processing in bulk mode.
Public methodCode exampleAddJob(String, String, EmailAddressCollection, IDataReader, Boolean, Boolean)
Puts a "mail merge over data reader" job onto waiting list for subsequent processing in bulk mode.
Public methodCode exampleAddJob(String, String, EmailAddressCollection, DataTable, Object, Boolean, Boolean)
Puts a "mail merge over database" job onto waiting list for subsequent processing in bulk mode.
Public methodCode exampleAuthPopBeforeSmtp
Authenticates the user on a mail server using POP-before-SMTP authentication.
Public methodAuthPopBeforeSmtpAsync
Public methodCode exampleBeginAuthPopBeforeSmtp Obsolete.
Begins an asynchronous request for a POP-before-SMTP authentication on a mail server.
Public methodCode exampleBeginConnect Obsolete.
Begins an asynchronous request for connecting to an SMTP server.
Public methodBeginDisconnect Obsolete.
Begins an asynchronous request for a disconnection from the server.
Public methodCode exampleBeginExecuteCustomCommand Obsolete.
Begins an asynchronous request for sending the specified user-defined command to the server and getting the response.
Public methodCode exampleBeginHello Obsolete.
Begins an asynchronous request for sending initial greeting to the SMTP server.
Public methodCode exampleBeginLogin Obsolete.
Begins an asynchronous request for authenticating the user on the SMTP server.
Public methodCode exampleBeginRelayFromEmlFile Obsolete.
Begins an asynchronous request for relaying a mail message to recipients.
Public methodCode exampleBeginSend Obsolete.
Begins an asynchronous request for sending a mail message to recipients.
Public methodCode exampleBeginSendJobs Obsolete.
Begins an asynchronous request to process the pending jobs and send out the resulting e-mails.
Public methodCode exampleBeginStartTls Obsolete.
Begins an asynchronous request to start TLS/SSL negotiation with the server.
Public methodCode exampleConnect
Connects to an SMTP server.
Public methodConnectAsync
Public methodDisconnect
Disconnects from the SMTP server and releases any used resources.
Public methodDisconnectAsync
Public methodDispose
Closes opened network connections (if any) and releases any used system resources.
Protected methodDispose(Boolean)
When overridden in a derived class, must release unmananged and optionally managed resources used by the component.
Public methodEndAuthPopBeforeSmtp
Ends the pending asynchronous request for POP-before-SMTP authentication on a mail server.
Public methodEndConnect
Ends the pending asynchronous request for connecting to the SMTP server.
Public methodEndDisconnect
Ends a pending asynchronous disconnection request.
Public methodEndExecuteCustomCommand
Ends the pending asynchronous request for sending user-defined command to the server.
Public methodEndHello
Ends the pending asynchronous request for sending a greeting to the SMTP server.
Public methodEndLogin
Ends the pending asynchronous request for authenticating the user on the SMTP server.
Public methodEndRelayFromEmlFile
Ends the pending asynchronous request for relaying the message to the recipients.
Public methodEndSend
Ends the pending asynchronous request for sending the message to the recipients.
Public methodEndSendJobs
Ends the pending asynchronous request for processing the pending jobs and sending out the resulting e-mails.
Public methodEndStartTls
Ends a pending asynchronous TLS/SSL negotiation request.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodCode exampleExecuteCustomCommand
Sends user-defined command to the server and receives the server response to this command.
Public methodExecuteCustomCommandAsync
async/await version of ExecuteCustomCommand(String).
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetAcceptedRecipients
Returns the list of the recipients accepted by the SMTP server.
Public methodGetCurrentSmtpServerIndex
Returns SmtpServers collection's index of the server to which the component is connected or will connect on the next connection attempt.
Public methodGetErrorDescription
Returns a textual description of the last error.
Public methodCode exampleGetExtension
Returns the name or parameters of the specified ESMTP capability.
Public methodCode exampleGetExtensions
Returns a reference to the key-value list of the server capabilities.
Public methodGetExtensionValue
Returns the parameters of the specified ESMTP capability, or an empty string if the capability has no parameters.
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetMaxMessageSize
Returns the maximum length of the message (in bytes) which is allowed by the SMTP server in order to accept the message from the client.
Public methodCode exampleGetMXHosts
Retrieves the list of hosts willing to accept mail for the given domain.
Public methodGetMXHostsAsync
async/await version of GetMXHosts(String).
Public methodCode exampleGetPtrData
Retrieves the list of domain names for the specified IP address.
Public methodGetPtrDataAsync
async/await version of GetPtrData(String).
Public methodGetRefusedRecipients
Returns the list of the recipients rejected by the SMTP server.
Public methodGetServerResponse
Returns the last response from the server.
Public methodGetServerResponseCode
Returns an integer value containing the status code of the last SMTP operation.
Public methodGetSocket
Returns the underlying Socket MailBee uses for the current SMTP connection.
Public methodGetSocketError
Returns a Win32 error code of the last socket-related error.
Public methodGetStream
Returns the underlying Stream MailBee uses for the current network connection.
Public methodCode exampleGetSupportedAuthMethods
Returns a set of flags indicating which authentication methods are supported by the server.
Public methodCode exampleGetTxtData
Retrieves the list of TXT strings of DNS data of the specified domain.
Public methodGetTxtDataAsync
async/await version of GetTxtData(String).
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodCode exampleHello
Sends initial greeting to the SMTP server.
Public methodHelloAsync
Public methodCode exampleLogin
Authenticates the user on the SMTP server if ESMTP authentication is enabled.
Public methodLoginAsync
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodNoop
Sends a NOOP command to the server.
Public methodNoopAsync
Protected methodOnConnected
Used by MailBee to raise Connected event.
Protected methodOnDataReceived
Used by MailBee to raise DataReceived event.
Protected methodOnDataSent
Used by MailBee to raise DataSent event.
Protected methodOnDisconnected
Used by MailBee to raise Disconnected event.
Protected methodOnErrorOccurred
Used by MailBee to raise ErrorOccurred event.
Protected methodOnFinishingJob
Used by MailBee to raise FinishingJob event.
Protected methodOnHostResolved
Used by MailBee to raise HostResolved event.
Protected methodOnLoggedIn
Used by MailBee to raise LoggedIn event.
Protected methodOnLogNewEntry
Used by MailBee to raise LogNewEntry event.
Protected methodOnLowLevelDataReceived
Used by MailBee to raise LowLevelDataReceived event.
Protected methodOnLowLevelDataSent
Used by MailBee to raise LowLevelDataSent event.
Protected methodOnMergingMessage
Used by MailBee to raise MergingMessage event.
Protected methodOnMessageDataChunkSent
Used by MailBee to raise MessageDataChunkSent event.
Protected methodOnMessageDirectSendDone
Used by MailBee to raise MessageDirectSendDone event.
Protected methodOnMessageMXLookupDone
Used by MailBee to raise MessageMXLookupDone event.
Protected methodOnMessageNotSent
Used by MailBee to raise MessageNotSent event.
Protected methodOnMessageRecipientSubmitted
Used by MailBee to raise MessageRecipientSubmitted event.
Protected methodOnMessageSenderSubmitted
Used by MailBee to raise MessageSenderSubmitted event.
Protected methodOnMessageSent
Used by MailBee to raise MessageSent event.
Protected methodOnMessageSubmittedToPickupFolder
Used by MailBee to raise MessageSubmittedToPickupFolder event.
Protected methodOnMessageSubmittedToServer
Used by MailBee to raise MessageSubmittedToServer event.
Protected methodOnSendingMessage
Used by MailBee to raise SendingMessage event.
Protected methodOnSocketConnected
Used by MailBee to raise SocketConnected event.
Protected methodOnSocketCreating
Used by MailBee to raise SocketCreating event.
Protected methodOnSubmittingMessageToPickupFolder
Used by MailBee to raise SubmittingMessageToPickupFolder event.
Protected methodOnTlsStarted
Used by MailBee to raise TlsStarted event.
Protected methodOnTransientErrorOccurred
Used by MailBee to raise TransientErrorOccurred event.
Public methodStatic memberCode exampleQuickSend(MailMessage)
Sends a mail message, in a single line of code.
Public methodStatic memberCode exampleQuickSend(String, String, String, String)
Sends a mail message, in a single line of code.
Public methodStatic memberCode exampleQuickSend(String, String, String, String, String, String, String)
Sends a mail message, in a single line of code.
Public methodCode exampleRelayFromEmlFile(String, String, EmailAddressCollection)
Relays (sends without any modifications) the mail message previously saved as an .EML file, to the specified recipients.
Public methodCode exampleRelayFromEmlFile(String, String, String)
Relays (sends without any modifications) the mail message previously saved as an .EML file, to the specified recipients.
Public methodRelayFromEmlFileAsync(String, String, EmailAddressCollection)
Public methodRelayFromEmlFileAsync(String, String, String)
Public methodResetMessage
Resets all properties of Message object to defaults. Delivery Status Notification settings (DeliveryNotification object) are also reset.
Public methodResetState
Resets the internal state of the component.
Public methodCode exampleRetryFailedJobs
Puts all failed send-mail jobs back into the queue.
Public methodCode exampleSend
Sends the mail message to the recipients specified in the message.
Public methodCode exampleSend(String, EmailAddressCollection)
Sends the mail message to the specified recipients.
Public methodCode exampleSend(String, String)
Sends the mail message to the specified recipients e-mail addresses.
Public methodSendAsync
Public methodSendAsync(String, EmailAddressCollection)
async/await version of Send(String, EmailAddressCollection).
Public methodSendAsync(String, String)
async/await version of Send(String, String).
Public methodCode exampleSendJobs
Sends out all e-mails in the pending jobs queue (including e-mails generated via mail merge).
Public methodSendJobsAsync
Public methodCode exampleSendMailMerge(String, EmailAddressCollection, DataTable)
Creates a series of e-mails based on an e-mail message template and a data table and sends these e-mails out.
Public methodCode exampleSendMailMerge(String, EmailAddressCollection, IDataReader)
Creates a series of e-mails based on an e-mail message template and a data reader and sends these e-mails out.
Public methodSendMailMergeAsync(String, EmailAddressCollection, DataTable)
Public methodSendMailMergeAsync(String, EmailAddressCollection, IDataReader)
Public methodCode exampleStartTls
Requests the mail server to start TLS/SSL negotiation and protect the existing connection with a security layer.
Public methodStartTlsAsync
Public methodCode exampleStopJobs
Notifies MailBee to stop processing jobs, completing sending out of all messages currently being processed.
Public methodCode exampleSubmitJobsToPickupFolder
Saves all e-mails in the pending jobs queue (including e-mails generated via mail merge) as files in the pickup folder of MailBee.NET Queue or IIS SMTP service.
Public methodSubmitJobsToPickupFolderAsync
Public methodCode exampleSubmitToPickupFolder(String, Boolean)
Saves the mail message as a file in the pickup folder of MailBee.NET Queue or IIS SMTP service.
Public methodCode exampleSubmitToPickupFolder(String, String, String, EmailAddressCollection, Boolean)
Saves the mail message as a file in the pickup folder of MailBee.NET Queue or IIS SMTP service.
Public methodCode exampleSubmitToPickupFolder(String, String, String, String, Boolean)
Saves the mail message as a file in the pickup folder of MailBee.NET Queue or IIS SMTP service.
Public methodSubmitToPickupFolderAsync(String, Boolean)
async/await version of SubmitToPickupFolder(String, Boolean).
Public methodSubmitToPickupFolderAsync(String, String, String, EmailAddressCollection, Boolean)
Public methodSubmitToPickupFolderAsync(String, String, String, String, Boolean)
Public methodCode exampleTestSend
Tests sending a mail message to the recipients without actual submitting of the message data.
Public methodTestSendAsync
async/await version of TestSend(SendFailureThreshold).
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodStatic memberCode exampleValidateEmailAddressSyntax
Verifies if the specified string is a correctly formatted e-mail address.
Public methodWait Obsolete.
Waits until the currently running (if any) asynchronous method is finished.
Public methodWait(Int32) Obsolete.
Waits the completion of the currently running (if any) asynchronous method for the specified amount of time.
Top
Properties
  NameDescription
Public propertyCode exampleBcc
Gets or sets EmailAddressCollection object specifying BCC: recipients of the message.
Public propertyCode exampleBodyHtmlText
Gets or sets HTML version of the message body.
Public propertyCode exampleBodyPlainText
Gets or sets plain-text version of the message body.
Public propertyCode exampleCc
Gets or sets EmailAddressCollection object specifying CC: recipients of the message.
Public propertyCode exampleCharset
Gets or sets charset of the message.
Public propertyConversion8BitTo7bit
Gets or sets if (and how) the component should perform 8bit-to-7bit conversion of the message data if the given SMTP server does not support transmission of 8bit data but the message does contain such data.
Public propertyDeliveryNotification
Provides access to properties which control when and how ESMTP Delivery Status Notification messages will be sent to the message sender.
Public propertyCode exampleDirectSendDefaults
Provides access to the default SMTP server settings to be used when connecting to SMTP servers discovered by MailBee via DNS MX lookup.
Public propertyCode exampleDnsServers
Gets the DnsServerCollection object containing the list of DNS servers to be used for DNS MX lookup.
Public propertyCode exampleFrom
Gets or sets EmailAddress object specifying the message sender.
Public propertyIsAborted
Indicates whether Abort method has been called for the component.
Public propertyIsBusy
Indicates whether the component is performing a lengthy operation.
Public propertyIsConnected
Indicates whether the component is connected to the server.
Public propertyIsLoggedIn
Indicates whether the component has already successfully authenticated on the server and logged in the user account.
Public propertyIsSmtpContext
Indicates whether the component is currently operating in a single thread mode, and the current connection (if any) is an SMTP connection.
Public propertyIsSslConnection
Indicates whether the current connection (if any) is secured with TLS/SSL layer.
Public propertyJobsFailed
Gets the list of e-mail tasks failed during processing.
Public propertyJobsPending
Gets the list of send-mail (sending a single message or mail-merge) tasks ready for processing.
Public propertyJobsRunning
Gets the list of e-mail tasks being processed right now.
Public propertyJobsSuccessful
Gets the list of successfully processed e-mail tasks.
Public propertyCode exampleJobsSyncRoot
Gets the object to be used for synchronized access to the jobs collections.
Public propertyLastResult
Gets a numeric code of the last error.
Public propertyStatic memberLicenseKey Obsolete.
Assigns the license key.
Public propertyCode exampleLog
Gets the object used for logging MailBee activities into a file or memory buffer.
Public propertyCode exampleMaxThreadCount
Gets or sets the maximum number of threads MailBee may create during send mail operations.
Public propertyCode exampleMessage
Gets or sets the mail message which will be sent by the component on Send method call.
Public propertyRaiseEvents
Gets or sets whether the component will raise any events.
Public propertyRaiseEventsViaMessageLoop
Gets or sets whether the events will be raised on the message loop of the application or not.
Public propertyCode exampleReplyTo
Gets or sets EmailAddressCollection object specifying e-mail addresses to which the replies to this message should be sent.
Public propertyRequestEncoding
Gets or sets the encoding used to convert a string into a bytes stream which is then sent to the server.
Public propertyResponseEncoding
Gets or sets the encoding used to convert a byte data received from the server into a string.
Public propertySite
Gets or sets the object to be used as a site for the component.
Public propertyCode exampleSmtpServers
Gets the SmtpServerCollection object containing the list of SMTP relay servers to be used for sending mail.
Public propertyStopJobsOnError
Gets or sets if processing of the jobs must be stopped if an error occurs.
Public propertyCode exampleSubject
Gets or sets the subject of the message.
Public propertySynchronizingObject
Gets or sets the object used to marshal the calls of the event handlers.
Public propertyThrowExceptions
Gets or sets whether the component will throw exceptions on errors.
Public propertyCode exampleTo
Gets or sets EmailAddressCollection object specifying To: recipients of the message.
Public propertyTrialDaysLeft
Gets the number of days left to the date of the trial license key expiration.
Public propertyVersion
Gets the version of the MailBee assembly.
Top
Events
  NameDescription
Public eventCode exampleConnected
Occurs when the connection with the server is successfully established.
Public eventCode exampleDataReceived
Occurs when data is received from the network.
Public eventCode exampleDataSent
Occurs when data is sent to the network.
Public eventCode exampleDisconnected
Occurs when the connection with the server gets closed.
Public eventDisposed
Occurs after the component was disposed.
Public eventCode exampleErrorOccurred
Occurs when the MailBeeException is thrown.
Public eventFinishingJob
Occurs when the component is about to finish a job of sending an individual e-mail message or a mail merge series.
Public eventCode exampleHostResolved
Occurs when the SMTP server name is successully resolved into IP address(es).
Public eventCode exampleLoggedIn
Occurs when the component successfully authenticates the user on the SMTP server and logs in the user account.
Public eventCode exampleLogNewEntry
Occurs when an entry is written into the log file (or into the memory buffer if Smtp.Log.MemoryLog is true).
Public eventCode exampleLowLevelDataReceived
Occurs when data is received from the connected socket.
Public eventCode exampleLowLevelDataSent
Occurs when data is sent to the connected socket.
Public eventCode exampleMergingMessage
Occurs when the component is about to merge the e-mail template with a single data table row.
Public eventCode exampleMessageDataChunkSent
Occurs on progress of sending message source data to the SMTP server.
Public eventCode exampleMessageDirectSendDone
Occurs in direct send mode when the component finished submitting the mail message to all SMTP MX servers of recipients domains.
Public eventCode exampleMessageMXLookupDone
Occurs in direct send mode after the component finished DNS MX lookup of SMTP MX servers of recipients domains.
Public eventCode exampleMessageNotSent
Occurs when the message was not sent due to an error.
Public eventCode exampleMessageRecipientSubmitted
Occurs each time the next recipient in the mail message recipients list is accepted or refused by the SMTP server.
Public eventCode exampleMessageSenderSubmitted
Occurs after the sender of the mail message was successfully submitted to the SMTP server.
Public eventCode exampleMessageSent
Occurs after the message was successfully sent.
Public eventCode exampleMessageSubmittedToPickupFolder
Occurs after the current message was saved to MailBee.NET Queue or IIS SMTP pickup folder.
Public eventCode exampleMessageSubmittedToServer
Occurs each time the message is successfully submitted to the SMTP server.
Public eventCode exampleSendingMessage
Occurs when the message is about to be sent.
Public eventCode exampleSocketConnected
Occurs when the SMTP server accepts the connection attempt and opens the transmission channel between the remote host (SMTP server) and the client (MailBee).
Public eventCode exampleSocketCreating
Occurs when MailBee needs a new socket object for establishing a connection with the SMTP server.
Public eventCode exampleSubmittingMessageToPickupFolder
Occurs when the message is about to be saved into MailBee.NET Queue or IIS SMTP pickup folder.
Public eventCode exampleTlsStarted
Occurs when the connection with the server becomes secure.
Public eventCode exampleTransientErrorOccurred
Occurs on a transient SMTP error which can be ignored because at least one fail-over SMTP server hasn't been tried yet.
Top
Remarks
You can perform the following operations using this class:
  • Send messages to an SMTP server
  • Perform mail merge over database to easily create and send bulk mail
  • Send messages in direct send mode (using MX lookup) when no SMTP relay server is available
  • Specify multiple SMTP and DNS servers for increased reliability and speed of sending very large volumes of messages
  • Authenticate on an SMTP server using a number of methods (including secure authentication methods, OAuth2, and POP-before-SMTP)
  • Take advantage of ESMTP pipelining which dramatically speeds up sending messages to multiple recipients
  • Take advantage of ESMTP chunking which significantly speeds up sending large messages
  • Track message delivery using ESMTP Delivery Status Notifications
  • Send messages with a single line of code (using static methods)
  • Submit messages directly to MailBee.NET Queue or IIS SMTP pickup service
  • Send messages through TLS/SSL secure connection
  • Establish connection via a proxy server (SOCKS4, SOCKS5, and HTTP proxy are supported)
  • Perform DNS MX, TXT, and reverse DNS queries
Also, DomainKeys object uses Smtp object to perform DNS TXT queries for verification of DomainKeys signatures of e-mails.
Note Note
Database-related functionality (such as mail merge over database) is not available in .NET Core and UWP.
Examples
This sample sends plain-text message to the SMTP server. We also disable ESMTP CHUNKING here (it improves sending performance but some servers support it incorrectly, so you may try both methods, with CHUNKING on and off).
// To use the code below, import MailBee namespaces at the top of your code.
using MailBee;
using MailBee.SmtpMail;

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

Smtp mailer = new Smtp();

// Set the message fields.
mailer.From.AsString = "John Doe <jdoe@domain1.com>";
mailer.To.AsString = "Bill Smith <b.smith@domain2.com>";
mailer.Subject = "Weekly newsletter";
mailer.BodyPlainText = "This is the newsletter contents";

// Specify the server to use. If your server does not require authentication, 
// just remove last 2 parameters.
mailer.SmtpServers.Add("smtp.domain1.com", "jdoe", "secret");

// Disable ESMTP CHUNKING even if the server claims CHUNKING is supported
// (often helps with MS Exchange servers).
mailer.SmtpServers[0].SmtpOptions = ExtendedSmtpOptions.NoChunking;

// Send the message.
mailer.Send();

Console.WriteLine("The message was successfully submitted to the server.");
See Also