Ferrysoft SMTP Module

SMTP Module

Overview

The Ferrysoft SMTP Module is a client class to send emails to an SMTP server. The SMTP Module is provided in source code form (Visual Basic 2005/2008 compatible and Visual C# 2005/2008 compatible). It is intended for developers, to incorporate into their own applications, in order to provide SMTP client support to the application. The module can be used, royalty-free, by any individual or organisation that purchases the module. As the module is provided in source code form, it can be modified as necessary after purchase, provided that any derived module is not distributed, in source code form, to a third party. The module can be incorporated into a commercial product and sold to third parties, in compiled format, provided that the purpose of the commercial product is not simply to act as a wrapper for the SMTP Module.

Buy It

The SMTP Module is available for download in a password protected zip file. A royalty-free source code licence to use the SMTP Module can be purchased. On completion of the purchase, Ferrysoft will email the password of the protected zip file to the purchaser to enable the SMTP Module to be extracted for use.

Download

ferrysoft.smtp.zip

The SMTP Module is priced in Pounds Sterling (GBP), US Dollars (USD) and Euros (EUR).

Ferrysoft SMTP Module Price Google PayPal
Royalty-free source code licence (GBP) £49
Royalty-free source code licence (USD) $99 -
Royalty-free source code licence (EUR) €75 -

Summary

The Ferrysoft SMTP Module is a wrapper class for the System.Net.Mail namespace. It has the following advantages over using the System.Net.Mail namespace natively:

  • Encapsulates most references to the System.Net.Mail namespace within the class.
  • Provides simple parameterised methods instead of having to use multiple namespace properties.
  • Provides an easy way of setting all email address fields of the message.
  • Provides an easy way of including alternate views with the message.
  • Provides an easy way of including attachments with the message.
  • Provides an easy way of sending the message.

Summary of methods provided by the class

The methods provided by the class are described in the following table.

Method Use
Compose Used to set the email message level properties such as the subject and body of the message. There are two variants of the Compose method. The first accepts the minimum parameters of subject and body. The second accepts a full set of parameters for the message. The Compose method is intended to be used once for each new email message.
SetFrom Used to set the From: field of the email. There are two variants of the SetFrom method. The first accepts just an email address, for example "john.doe@example.com". The second accepts an email address and name, for example "john.doe@example.com" and "John Doe". The SetFrom method is intended to be used once for each email message.
SetSender Used to set the Sender: field of the email. There are two variants of the SetSender method. The first accepts just an email address, for example "john.doe@example.com". The second accepts an email address and name, for example "john.doe@example.com" and "John Doe". The SetSender method is intended to be used once for each email message, if the Sender: field is required to be set.
SetReplyTo Used to set the Reply-To: field of the email. There are two variants of the SetReplyTo method. The first accepts just an email address, for example "john.doe@example.com". The second accepts an email address and name, for example "john.doe@example.com" and "John Doe". The SetReplyTo method is intended to be used once for each email message, if the Reply-To: field is required to be set.
AppendTo Used to append an email address to the collection of email addresses in the To: field of the email. There are two variants of the AppendTo method. The first accepts just an email address, for example "john.doe@example.com". The second accepts an email address and name, for example "john.doe@example.com" and "John Doe". The AppendTo method is intended to be used for each email address that needs to appear in the To: field of the email message.
AppendCarbonCopy Used to append an email address to the collection of email addresses in the Cc: field of the email. There are two variants of the AppendCarbonCopy method. The first accepts just an email address, for example "john.doe@example.com". The second accepts an email address and name, for example "john.doe@example.com" and "John Doe". The AppendCarbonCopy method is intended to be used for each email address that needs to appear in the Cc: field of the email message.
AppendBlindCarbonCopy Used to append an email address to the collection of email addresses in the Bcc: field of the email. There are two variants of the AppendBlindCarbonCopy method. The first accepts just an email address, for example "john.doe@example.com". The second accepts an email address and name, for example "john.doe@example.com" and "John Doe". The AppendBlindCarbonCopy method is intended to be used for each email address that needs to appear in the Bcc: field of the email message.
AppendAlternateView Used to append an alternate view to the email message. Alternate views allow the recipient's email client to display the email in an appropriate format according to the capabilities of the email client. For example, an email message could be sent in plain text format with an alternate view in HTML format. The recipient's email client would display the message in HTML format if it had the capability, otherwise it would display the message in plain text format. The AppendAlternateView method is intended to be used once for each alternate view required.
AppendAttachment Used to append an attachment to the email message. The AppendAttachment method is intended to be used once for each attachment required.
Send Used to send the email message to the server. There are two variants of the Send method. The first accepts the minimum parameter of server name. The second accepts a full set of parameters for the server including authentication credentials if the server requires authentication. The Send method is intended to be used once for each email message.

Compose methods

Syntax

Visual Basic
Friend Overloads Sub Compose( _
    ByVal MessageSubject As String, _
    ByVal MessageBody As String)

Friend Overloads Sub Compose( _
    ByVal MessageSubject As String, _
    ByVal MessageBody As String, _
    ByVal MessageSubjectEncoding As System.Text.Encoding, _
    ByVal MessageBodyEncoding As System.Text.Encoding, _
    ByVal MessageIsBodyHtml As Boolean, _
    ByVal MessagePriority As System.Net.Mail.MailPriority, _
    ByVal MessageDeliveryNotificationOptions As _
        System.Net.Mail.DeliveryNotificationOptions)
C#
internal void Compose(
    string MessageSubject,
    string MessageBody)

internal void Compose(
    string MessageSubject,
    string MessageBody,
    System.Text.Encoding MessageSubjectEncoding,
    System.Text.Encoding MessageBodyEncoding,
    bool MessageIsBodyHtml,
    System.Net.Mail.MailPriority MessagePriority,
    System.Net.Mail.DeliveryNotificationOptions
        MessageDeliveryNotificationOptions)

Parameters

MessageSubject
The text for the Subject: property, for example, "Email test subject".
MessageBody
The text of the message, for example, "Email test message".
MessageSubjectEncoding
The encoding of the subject. The parameter can be set to any of the following enumerations of System.Text.Encoding:
ASCII
BigEndianUnicode
Default
Unicode
UTF32
UTF7
UTF8 (default)
MessageBodyEncoding
The encoding of the message. The parameter can be set to any of the following enumerations of System.Text.Encoding:
ASCII
BigEndianUnicode
Default
Unicode
UTF32
UTF7
UTF8 (default)
MessageIsBodyHtml
Indicates whether the body of the message is in HTML format. The parameter can be either of the following:
True - HTML format
False - Not HTML format (default)
MessagePriority
The priority of the message. The parameter can be set to any of the following enumerations of System.Net.Mail.MailPriority:
High
Low
Normal (default)
MessageDeliveryNotificationOptions
The delivery notification options of the message. The parameter can be set to any of the following enumerations of System.Net.Mail.DeliveryNotificationOptions:
Delay
Never
None (default)
OnFailure
OnSuccess

SetFrom / SetSender / SetReplyTo methods

Syntax

Visual Basic
Friend Overloads Sub SetFrom( _
    ByVal EmailAddress As String)

Friend Overloads Sub SetFrom( _
    ByVal EmailAddress As String, _
    ByVal EmailName As String)

Friend Overloads Sub SetSender( _
    ByVal EmailAddress As String)

Friend Overloads Sub SetSender( _
    ByVal EmailAddress As String, _
    ByVal EmailName As String)

Friend Overloads Sub SetReplyTo( _
    ByVal EmailAddress As String)

Friend Overloads Sub SetReplyTo( _
    ByVal EmailAddress As String, _
    ByVal EmailName As String)
C#
internal void SetFrom(
    string EmailAddress)

internal void SetFrom(
    string EmailAddress,
    string EmailName)

internal void SetSender(
    string EmailAddress)

internal void SetSender(
    string EmailAddress,
    string EmailName)

internal void SetReplyTo(
    string EmailAddress)

internal void SetReplyTo(
    string EmailAddress,
    string EmailName)

Parameters

EmailAddress
The email address, for example "john.doe@example.com".
EmailName
The email name, for example, "John Doe". Default is "".

AppendTo / AppendCarbonCopy / AppendBlindCarbonCopy methods

Syntax

Visual Basic
Friend Overloads Sub AppendTo( _
    ByVal EmailAddress As String)

Friend Overloads Sub AppendTo( _
    ByVal EmailAddress As String, _
    ByVal EmailName As String)

Friend Overloads Sub AppendCarbonCopy( _
    ByVal EmailAddress As String)

Friend Overloads Sub AppendCarbonCopy( _
    ByVal EmailAddress As String, _
    ByVal EmailName As String)

Friend Overloads Sub AppendBlindCarbonCopy( _
    ByVal EmailAddress As String)

Friend Overloads Sub AppendBlindCarbonCopy( _
    ByVal EmailAddress As String, _
    ByVal EmailName As String)
C#
internal void AppendTo(
    string EmailAddress)

internal void AppendTo(
    string EmailAddress,
    string EmailName)

internal void AppendCarbonCopy(
    string EmailAddress)

internal void AppendCarbonCopy(
    string EmailAddress,
    string EmailName)

internal void AppendBlindCarbonCopy(
    string EmailAddress)

internal void AppendBlindCarbonCopy(
    string EmailAddress,
    string EmailName)

Parameters

EmailAddress
The email address, for example "john.doe@example.com".
EmailName
The email name, for example, "John Doe". Default is "".

AppendAlternateView method

Syntax

Visual Basic
Friend Overloads Sub AppendAlternateView( _
    ByVal AlternateView As System.Net.Mail.AlternateView)
C#
internal void AppendAlternateView(
    System.Net.Mail.AlternateView AlternateView)

Parameters

AlternateView
An alternate view. See example for how to create an alternate view object.

AppendAttachment method

Syntax

Visual Basic
Friend Overloads Sub AppendAttachment( _
    ByVal Attachment As System.Net.Mail.Attachment)
C#
internal void AppendAttachment(
    System.Net.Mail.Attachment Attachment)

Parameters

Attachment
An attachment. See example for how to create an attachment object.

Send methods

Syntax

Visual Basic
Friend Overloads Sub Send( _
    ByVal SmtpServer As String)

Friend Overloads Sub Send( _
    ByVal SmtpServer As String, _
    ByVal SmtpPort As Integer, _
    ByVal SmtpEncrypted As Boolean, _
    ByVal SmtpTimeout As Integer, _
    ByVal SmtpAuthenticated As Boolean, _
    ByVal SmtpUsername As String, _
    ByVal SmtpPassword As String)
C#
internal void Send(
    string SmtpServer)

internal void Send(
    string SmtpServer,
    int SmtpPort,
    bool SmtpEncrypted,
    int SmtpTimeout,
    bool SmtpAuthenticated,
    string SmtpUsername,
    string SmtpPassword)

Parameters

SmtpServer
The server name of the SMTP Server. For example, the fictitious server "smtp.example.com".
SmtpPort
The server port number. Default is 25.
SmtpEncrypted
Indicates whether the server requires an encrypted connection. The parameter can be either of the following:
True - Requires an encrypted connection
False - Does not require an encrypted connection (default)
SmtpTimeout
The server connection timeout in seconds. Default is 30.
SmtpAuthenticated
Indicates whether the server requires an authenticated connection. The parameter can be either of the following:
True - Requires an authenticated connection
False - Does not require an authenticated connection (default)
SmtpUsername
The username if the SmtpAuthenticated parameter is set to true. Default is "".
SmtpPassword
The password if the SmtpAuthenticated parameter is set to true. Default is "".

Example Use

The code below shows an example of how to use the SMTP client class.

Visual Basic
Dim SmtpClient As Ferrysoft.Smtp
Dim Attachment As System.Net.Mail.Attachment
Dim AlternateView As System.Net.Mail.AlternateView
Dim ContentType As System.Net.Mime.ContentType
'
'   Create the SMTP client.
'
SmtpClient = New Ferrysoft.Smtp()
'
'   This example sends a plain text message.
'
SmtpClient.Compose("Example 1 message subject", _
    "Example plain text message")
SmtpClient.SetFrom("jane.doe@example.com")
SmtpClient.AppendTo("john.doe@example.com")
SmtpClient.Send("smtp.example.com")
'
'   This example sends an HTML message with
'   multiple addresses for To:, Cc: and Bcc:.
'   It also sets the Sender: and Reply-To:
'   fields and sends the message with high
'   priority.
'
SmtpClient.Compose("Example 2 message subject", _
    "<html><body>Example <b>HTML</b> message</body></html>", _
    System.Text.Encoding.UTF8, _
    System.Text.Encoding.UTF8, _
    True, _
    System.Net.Mail.MailPriority.High, _
    System.Net.Mail.DeliveryNotificationOptions.None)
SmtpClient.SetFrom("jane.doe@example.com", "Jane Doe")
SmtpClient.SetSender("gary.doe@example.com", "Gary Doe")
SmtpClient.SetReplyTo("henrietta.doe@example.com", _
    "Henrietta Doe")
SmtpClient.AppendTo("john.doe@example.com", "John Doe")
SmtpClient.AppendTo("andy.doe@example.com")
SmtpClient.AppendTo("bill.doe@example.com", "Bill Doe")
SmtpClient.AppendCarbonCopy("cloe.doe@example.com", _
    "Cloe Doe")
SmtpClient.AppendCarbonCopy("david.doe@example.com")
SmtpClient.AppendBlindCarbonCopy("eileen.doe@example.com")
SmtpClient.AppendBlindCarbonCopy("fred.doe@example.com", _
    "Fred Doe")
SmtpClient.Send("smtp.example.com", _
    25, _
    False, _
    30, _
    True, _
    "myusername", _
    "mypassword")
'
'   This example sends a message with both
'   plain text and HTML views. This allows the
'   recipient to see either a plain text view or
'   an HTML view depending on the capabilities of
'   the recipient's email client.
'   The plain text view is composed in the message
'   body and the HTML view is attached as an
'   alternate view.
'   The message requests delivery notification on
'   success.
'   The message also has three attachments.
'
SmtpClient.Compose("Example 3 message subject", _
    "Example plain text message", _
    System.Text.Encoding.UTF8, _
    System.Text.Encoding.UTF8, _
    False, _
    System.Net.Mail.MailPriority.Normal, _
    System.Net.Mail.DeliveryNotificationOptions.OnSuccess)
SmtpClient.SetFrom("jane.doe@example.com", "Jane Doe")
SmtpClient.AppendTo("john.doe@example.com", "John Doe")
'
'   Append an alternate view in HTML format.
'
AlternateView = System.Net.Mail.AlternateView. _
    CreateAlternateViewFromString( _
    "<html><body>Example <b>HTML</b> message</body></html>", _
    System.Text.Encoding.UTF8, _
    System.Net.Mime.MediaTypeNames.Text.Html)
SmtpClient.AppendAlternateView(AlternateView)
'
'   Attach a Microsoft Word document.
'
Attachment = New System.Net.Mail.Attachment( _
    "C:\Test\Test1.docx", "application/msword")
Attachment.ContentDisposition.DispositionType = _
    System.Net.Mime.DispositionTypeNames.Attachment
SmtpClient.AppendAttachment(Attachment)
'
'   Attach a text file. Note that a ContentType
'   is used to prepare the attachment so that
'   the MediaType and CharSet can be explicitly
'   specified.
'
ContentType = New System.Net.Mime.ContentType()
ContentType.MediaType = _
    System.Net.Mime.MediaTypeNames.Text.Plain
ContentType.CharSet = System.Text.Encoding.UTF8.WebName
Attachment = New System.Net.Mail.Attachment( _
    "C:\Test\Test1.txt", ContentType)
Attachment.ContentDisposition.DispositionType = _
    System.Net.Mime.DispositionTypeNames.Attachment
SmtpClient.AppendAttachment(Attachment)
'
'   Attach a text file created from a string.
'
Attachment = System.Net.Mail.Attachment. _
    CreateAttachmentFromString( _
    "This is a text attachment", _
    "Test2.txt", _
    System.Text.Encoding.UTF8, _
    System.Net.Mime.MediaTypeNames.Text.Plain)
Attachment.ContentDisposition.DispositionType = _
    System.Net.Mime.DispositionTypeNames.Attachment
SmtpClient.AppendAttachment(Attachment)
SmtpClient.Send("smtp.example.com", _
    25, _
    False, _
    30, _
    False, _
    "", _
    "")
C#
Ferrysoft.Smtp SmtpClient;
System.Net.Mail.Attachment Attachment;
System.Net.Mail.AlternateView AlternateView;
System.Net.Mime.ContentType ContentType;
//
//  Create the SMTP client.
//
SmtpClient = new Ferrysoft.Smtp();
//
//  This example sends a plain text message.
//
SmtpClient.Compose("Example 1 message subject",
    "Example plain text message");
SmtpClient.SetFrom("jane.doe@example.com");
SmtpClient.AppendTo("john.doe@example.com");
SmtpClient.Send("smtp.example.com");
//
//  This example sends an HTML message with
//  multiple addresses for To:, Cc: and Bcc:.
//  It also sets the Sender: and Reply-To:
//  fields and sends the message with high
//  priority.
//
SmtpClient.Compose("Example 2 message subject",
    "<html><body>Example <b>HTML</b> message</body></html>",
    System.Text.Encoding.UTF8,
    System.Text.Encoding.UTF8,
    true,
    System.Net.Mail.MailPriority.High,
    System.Net.Mail.DeliveryNotificationOptions.None);
SmtpClient.SetFrom("jane.doe@example.com", "Jane Doe");
SmtpClient.SetSender("gary.doe@example.com", "Gary Doe");
SmtpClient.SetReplyTo("henrietta.doe@example.com",
    "Henrietta Doe");
SmtpClient.AppendTo("john.doe@example.com", "John Doe");
SmtpClient.AppendTo("andy.doe@example.com");
SmtpClient.AppendTo("bill.doe@example.com", "Bill Doe");
SmtpClient.AppendCarbonCopy("cloe.doe@example.com",
    "Cloe Doe");
SmtpClient.AppendCarbonCopy("david.doe@example.com");
SmtpClient.AppendBlindCarbonCopy("eileen.doe@example.com");
SmtpClient.AppendBlindCarbonCopy("fred.doe@example.com",
    "Fred Doe");
SmtpClient.Send("smtp.example.com",
    25,
    false,
    30,
    true,
    "myusername",
    "mypassword");
//
//  This example sends a message with both
//  plain text and HTML views. This allows the
//  recipient to see either a plain text view or
//  an HTML view depending on the capabilities of
//  the recipient's email client.
//  The plain text view is composed in the message
//  body and the HTML view is attached as an
//  alternate view.
//  The message requests delivery notification on
//  success.
//  The message also has three attachments.
//
SmtpClient.Compose("Example 3 message subject",
    "Example plain text message",
    System.Text.Encoding.UTF8,
    System.Text.Encoding.UTF8,
    false,
    System.Net.Mail.MailPriority.Normal,
    System.Net.Mail.DeliveryNotificationOptions.OnSuccess);
SmtpClient.SetFrom("jane.doe@example.com", "Jane Doe");
SmtpClient.AppendTo("john.doe@example.com", "John Doe");
//
//  Append an alternate view in HTML format.
//
AlternateView = System.Net.Mail.AlternateView.
    CreateAlternateViewFromString(
    "<html><body>Example <b>HTML</b> message</body></html>",
    System.Text.Encoding.UTF8,
    System.Net.Mime.MediaTypeNames.Text.Html);
SmtpClient.AppendAlternateView(AlternateView);
//
//  Attach a Microsoft Word document.
//
Attachment = new System.Net.Mail.Attachment(
    "C:\\Test\\Test1.docx", "application/msword");
Attachment.ContentDisposition.DispositionType =
    System.Net.Mime.DispositionTypeNames.Attachment;
SmtpClient.AppendAttachment(Attachment);
//
//  Attach a text file. Note that a ContentType
//  is used to prepare the attachment so that
//  the MediaType and CharSet can be explicitly
//  specified.
//
ContentType = new System.Net.Mime.ContentType();
ContentType.MediaType =
    System.Net.Mime.MediaTypeNames.Text.Plain;
ContentType.CharSet = System.Text.Encoding.UTF8.WebName;
Attachment = new System.Net.Mail.Attachment(
    "C:\\Test\\Test1.txt", ContentType);
Attachment.ContentDisposition.DispositionType =
    System.Net.Mime.DispositionTypeNames.Attachment;
SmtpClient.AppendAttachment(Attachment);
//
//  Attach a text file created from a string.
//
Attachment = System.Net.Mail.Attachment.
    CreateAttachmentFromString(
    "This is a text attachment",
    "Test2.txt",
    System.Text.Encoding.UTF8,
    System.Net.Mime.MediaTypeNames.Text.Plain);
Attachment.ContentDisposition.DispositionType =
    System.Net.Mime.DispositionTypeNames.Attachment;
SmtpClient.AppendAttachment(Attachment);
SmtpClient.Send("smtp.example.com",
    25,
    false,
    30,
    false,
    "",
    "");