Download v2.0 for .NET Framework, 125 KB Download
How to Start
It's very easy to start, just follow these steps:
  • Download TSSI .NET SMTP Component's release package and extract all files from the downloaded package to your local disk.
  • Add TSSI .NET SMTP Component.dll and Starksoft.Net.Proxy.dll (under "libs" folder) references to your project and import the corresponding namespaces in your code by your IDE / programming language way.
  • Now, you are enabled to write the (E)SMTP based eMailing code in your project!
    To coding with TSSI .NET SMTP Component, just refer to this documentation, the Sample Codes and / or the demos (under "demos" folder).

# Example of Adding References and Importing Namespaces

Add References (VB 2008)

Add References (VB)

Add References (C# 2008)

Add References (C#)

Import Namespaces (VB)

Imports TSSI.eMail
Imports Starksoft.Net.Proxy

Import Namespaces (C#)

using TSSI.eMail;
using Starksoft.Net.Proxy;
Library Reference
There are only two classes and one enumeration to make it easy to use: SecureProtocol enumeration, TMailMessage Class and TSMTP class.

# SecureProtocol Enumeration <Top>

Item Description
Purpose Describes the security connection protocol that used by TSMTP.Protocol property.
Namespace TSSI.eMail
Assembly TSSI .NET SMTP Component (in TSSI .NET SMTP Component.dll)
Members
  • None - normal SMTP connection, no security protocol.
  • SSL - uses the Secure Socket Layer (SSL) security connection protocol.
  • TLS - uses the Transport Layer Security (TLS) security connection protocol.
Supported .NET Framework Versions 2.0 or higher.

# TMailMessage Class <Top>

Overview <Top>

Item Description
Purpose Represents an e-mail message that can be sent using the TSMTP class.
Namespace TSSI.eMail
Assembly TSSI .NET SMTP Component (in TSSI .NET SMTP Component.dll)
Inheritance Hierarchy System.Object
      System.Net.Mail.MailMessage
            TSSI.eMail.TMailMessage
Supported .NET Framework Versions 2.0 or higher.

Members <Top>

This class is inherited from .NET System.Net.Mail.MailMessage, all native members please refer to MSDN to know more details. Here are the extended and overloaded members that made by TMailMessage.

Constructors <Top>
Name Description
Constructor TMailMessage() Initializes a new instance of the TMailMessage class with default values.

Properties <Top>
Name Data Type (VB / C#) Values Description Remarks
Property Attachments (Overloaded) Microsoft.VisualBasic.Collection (System.IO.FileInfo) The specific instanced System.IO.FileInfo collection. Gets or sets the attachments for the message. Please use this property to manage the attachments for the email. Because the native Attachments property of System.Net.Mail.MailMessage class contains the file content and much other extra information, so we overloaded it to get the lightweight Attachments property.
Property Receipt Boolean / bool True/False, default: False. Gets or sets whether need a read receipt or not. If you set it as True, you can use the ReceiptReceiver property to designate the receipt receiver.
Property ReceiptReceiver System.Net.Mail.MailAddress The specific instanced MailAddress class. Gets or sets the receipt receiver (name and email address) for the message. To validate this property, must set the Receipt property as True.
Property SendTime String / string A valid date time string, format: DDD, d MMM YYYY HH:MI:SS, e.g. Mon, 4 Oct 2010 09:03:08, default: system date time. Gets or sets the eMailing date and time for the message. Use this property to make the virtual eMailing time if necessary.

Methods <Top>
Name Declaration Parameters Return Values Description Remarks
Method CheckAddress VB: Public Shared Function CheckAddress(ByVal addr As String) As Boolean
C#: public static bool CheckAddress(string addr)
addr: a string that specifies the target email address to be checked. A Boolean value that indicated whether the email address is valid (True) or not (False). This utility method is used to check whether an e-mail address is valid or not. This is an additional method for checking the format of an email address.

# TSMTP Class <Top>

Overview <Top>

Item Description
Purpose Allows applications to send e-mail by using the Simple Mail Transfer Protocol (SMTP) and Extended SMTP (ESMTP).
Namespace TSSI.eMail
Assembly TSSI .NET SMTP Component (in TSSI .NET SMTP Component.dll)
Inheritance Hierarchy System.Object
      TSSI.eMail.TSMTP
Supported .NET Framework Versions 2.0 or higher.

Members <Top>

Constructors <Top>
Name Description
Constructor TSMTP() Initializes a new instance of the TSMTP class with default values.

Properties <Top>
Name Data Type (VB / C#) Values Description Remarks
Property Protocol SecureProtocol
(Enumeration)
SecureProtocol.None / SecureProtocol.SSL / SecureProtocol.TLS Gets or sets the security connection protocol of the SMTP server. If you are not sure, please contact the SMTP provider.
Property ProxyHost String / string The host name or IP address of the proxy server, default: empty string (do not use proxy server). Gets or sets the proxy server that requests are to be routed through. Supports host name and IP address, to send emails via the proxy server, must use it.
Property ProxyPasswd String / string The password for the corresponding user of the proxy server. Gets or sets the password to be sent on all requests through a proxy server that requires authentication. Only for Socks5 proxy protocol, to send emails via the authentication required proxy server, must use it.
Property ProxyPort Integer / int Between 1 and 65,535, default: 1080 (for Socks5 protocol). Gets or sets the remote port of the proxy server. To send emails via the proxy server and if it is not 1080, must use it.
Property ProxyProtocol ProxyType
(Enumeration)
ProxyType.Socks5 Gets or sets the proxy protocol of the proxy server. Currently only supports Socks5 - the common SMTP proxy protocol. ProxyType is an enumeration in Starksoft.Net.Proxy open source assembly (Starksoft.Net.Proxy.dll) that included in our product.
Property ProxyUser String / string The username of the proxy server, default: empty string (do not need authentication). Gets or sets the username to be sent on all requests through a proxy server that requires authentication. Only for Socks5 proxy protocol, to send emails via the authentication required proxy server, must use it.
Property SMTPPasswd String / string The password for the corresponding user on the SMTP server. Gets or sets the password for the SMTP server login name. To send emails via the authentication required SMTP server, must use it.
Property SMTPPort Integer / int Between 1 and 65,535, default: 25 (for SMTP protocol). Gets or sets the connection port of the SMTP server. -
Property SMTPServer String / string The host name of the SMTP server. Gets or sets the SMTP server address. We suggest you use the host name (e.g. smtp.gmail.com) for this property, do not use the IP address, because in the SMTP protocol, must use the host name after EHLO command.
Property SMTPUser String / string The username on the SMTP server, default: empty string (do not need authentication). Gets or sets the login name for connecting the SMTP server. To send emails via the authentication required SMTP server, must use it.

Methods <Top>
Name Declaration Parameters Return Values Description Remarks
Method About VB: Public Shared Sub About()
C#: public static void About()
- - Displays the About box, it contains the program and edition information. -
Method Connect VB: Public Function Connect(ByVal smtpServer As String, Optional ByVal smtpPort As Integer = 25) As Boolean
C#: public bool Connect(string smtpServer, int smtpPort)
smtpServer - specifies the SMTP server to connect. smtpPort - specifies the port for connecting to the SMTP server, default value is 25, if the port of your SMTP server is not 25, must designate it. True - the connection is established successfully.
False - Failed to connect to the SMTP server.
Connects to the designate SMTP server.
Method Disconnect VB: Public Sub Disconnect()
C#: public void Disconnect()
- - Disconnects from the connected SMTP server. -
Method SendMsg VB: Public Function SendMsg(ByVal tmm As TMailMessage) As Boolean
C#: public bool SendMsg(TMailMessage tmm)
tmm - a custom TMailMessage instance that is ready for sending. True - sent the eMail successfully. False - Failed to send the eMail. Sends the designate TMailMessage instance (eMail) after connected to the (E)SMTP server. When sending email, you can observe the sending progress in the Progress event. Before use it, must use Connect() method to establish the SMTP connection first, after used, must use Disconnect() method to disconnect from the SMTP server.
Method TestLogon VB: Public Function TestLogon() As Boolean
C#: public bool TestLogon()
- True - logged on the SMTP server successfully. False - Failed to log on the SMTP server. This utility method is used to test if the given user and password can be used to log on the SMTP server or not without sending. Before use it, must use Connect() method to establish the SMTP connection first, after used, must use Disconnect() method to disconnect from the SMTP server.

Events <Top>
Name Declaration Parameters Description Remarks
Event ErrorOccurred VB: Public Event ErrorOccurred(ByVal desc As String)
C#: public event TSSI.eMail.TSMTP.ErrorOccurredEventHandler ErrorOccurred
desc - the human-readable error description. An error has occurred during interacting with the SMTP server. Please use this event to get the error messages conveniently during interacting with the SMTP server.
Event Progress VB: Public Event Progress(ByVal id as Integer, ByVal desc as String)
C#: public event TSSI.eMail.TSMTP.ProgressEventHandler Progress
id - indicates current progress ID. desc - gives the details information of the corresponding progress ID.
The id and desc list as below:
  • 0 - Searching and connecting to the SMTP server...
  • 1 - Authenticating the logon information...
  • 2 - Sending the envelope...
  • 3 - Sending mail header...
  • 4 - Sending mail body...
  • 5 - Processing inner resources...
  • 6 - Processing the background picture...
  • 7 - Processing the background sound...
  • 8 - Sending the content...
  • 9 - Sending the inner resources...
  • 10 - Sending the background picture...
  • 11 - Sending the background sound...
  • 12 - Sending the attachments...
  • 13 - Sending the end tag...
  • 14 - Finished!
  • 15 - Quitting the SMTP session...
  • 16 - Disconnecting from the SMTP server...
Occurs when the eMailing progress was changed. Please use this event to get the progress when sending emails.
Sample Codes

# VB 2008 <Top>

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
' /*
' * TSSI .NET SMTP Component Demo (VB 2008)
' * 
' * Note: to test your own SMTP account and the received eMails,
' * you may modify the following code that starts with the "MBC" (may be changed) mark in the comment line.
' * 
' * To read the detailed documentation, please visit
' * https://www.automailsender.com/tssi-dotnet-smtp-component/help.htm
' * 
' * © TriSun Software Inc. All rights reserved.
' */

' Imports TDNSC's namespace first.
Imports TSSI.eMail
' Some native members of this namespace will be used in your code.
Imports System.Net.Mail
' The third-party open source proxy library.
Imports Starksoft.Net.Proxy
' Just for the attachments.
Imports System.IO
Imports Microsoft.VisualBasic
Imports System.Windows.Forms
Imports System

Public Class Main

   ' TSMTP instance (used to send eMail via the (E)SMTP protocol).
   Private WithEvents _tsmtp As New TSMTP
   ' TMailMessage instance (the eMail for sending).
   Private _tmm As New TMailMessage

   Private Sub bPlain_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bPlain.Click

      ' Send a plain text message.

      ' Compose your message.
      ComposeEmail()

      '''' Send message.
      ' Initialize the error messages box.
      tbErr.Text = "Error Messages"
      ' Initialize the progress box.
      tbProgress.Text = "Progress"
      '' Set the interface to be busy.
      Cursor.Current = Cursors.WaitCursor
      Me.Enabled = False
      ''
      With _tsmtp
         Try
            If .Connect(.SMTPServer, .SMTPPort) Then
               If .SendMsg(_tmm) Then
                  MsgBox("Sent the plain text message successfully!", MsgBoxStyle.Information)
               Else
                  MsgBox("Failed to send the plain text eMail, " & _
                         "please see the error messages to know about the reason.", MsgBoxStyle.Information)
               End If
            End If
         Catch ex As Exception
            ' Display the exception also.
            tbErr.Text = tbErr.Text & vbCrLf & ex.Message
         End Try
         ' Always disconnect from the SMTP server.        
         .Disconnect()
      End With
      '' Set the interface to be normal.
      Cursor.Current = Cursors.Default
      Me.Enabled = True
      ''
      ''''

   End Sub

   Private Sub bRich_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bRich.Click

      ' Send a rich text message.

      '' Compose your message.
      ComposeEmail()
      ' Set as HTML (rich text) email body.
      _tmm.IsBodyHtml = True
      ' The eMail content (plain text).
      _tmm.Body = "<html><body><h2>Hi, this is a test message that sent by " & _
                  "TSSI .NET SMTP Component.</h2><img src=""" & _
                  New DirectoryInfo(Application.StartupPath).Parent.Parent.FullName & _
                  "\atts\testatt.png"" /></body></html>"
      ''

      '''' Send message.
      ' Initialize the error messages box.
      tbErr.Text = "Error Messages"
      ' Initialize the progress box.
      tbProgress.Text = "Progress"
      '' Set the interface to be busy.
      Cursor.Current = Cursors.WaitCursor
      Me.Enabled = False
      ''
      With _tsmtp
         Try
            If .Connect(.SMTPServer, .SMTPPort) Then
               If .SendMsg(_tmm) Then
                  MsgBox("Sent the rich text message successfully!", MsgBoxStyle.Information)
               Else
                  MsgBox("Failed to send the rich text eMail, " & _
                         "please see the error messages to know about the reason.", MsgBoxStyle.Information)
               End If
            End If
         Catch ex As Exception
            ' Display the exception also.
            tbErr.Text = tbErr.Text & vbCrLf & ex.Message
         End Try
         ' Always disconnect from the SMTP server.
         .Disconnect()
      End With
      '' Set the interface to be normal.
      Cursor.Current = Cursors.Default
      Me.Enabled = True
      ''
      ''''
   End Sub
   Private Sub bCheck_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bCheck.Click

      ' Check the format of an eMail address.
      ' TMailMessage.CheckAddress() is a shared method, just call it from the class.

      ' The valid one. 
      MsgBox("[email protected] is " & _
             IIf(TMailMessage.CheckAddress("[email protected]"), "valid!", "invalid!").ToString, _
             MsgBoxStyle.Information)

      ' The invalid one.
      MsgBox("[email protected] is " & _
             IIf(TMailMessage.CheckAddress("[email protected]"), "valid!", "invalid!").ToString, _
             MsgBoxStyle.Information)
   End Sub

   Private Sub bAbout_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bAbout.Click

      ' Displays the About box, it contains the program and edition information.

      TSMTP.About()

   End Sub

   Private Sub bTestLogon_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bTestLogon.Click

      ' Test if the given user and password can be used to log on the SMTP server or not.

      ' Initialize the error messages box.
      tbErr.Text = "Error Messages"
      ' Initialize the progress box.
      tbProgress.Text = "Progress"

      '' Set the interface to be busy.
      Cursor.Current = Cursors.WaitCursor
      Me.Enabled = False
      ''
      With _tsmtp
         Try
            If .Connect(.SMTPServer, .SMTPPort) Then
               ' This utility method is used to test if the given user and 
               ' password can be used to log on the SMTP server or not.
               If .TestLogon() Then
                  MsgBox("Connected and logged in to the SMTP server successfully.", _
                         MsgBoxStyle.Information)
               Else
                  MsgBox("Cannot logged on the SMTP server according to your given information.", _
                         MsgBoxStyle.Exclamation)
               End If
            Else
               MsgBox("Cannot connect to the SMTP server according to your given information in your LAN.", _
                      MsgBoxStyle.Exclamation)
            End If
         Catch ex As Exception
            ' Display the exception also.
            tbErr.Text = tbErr.Text & vbCrLf & ex.Message
         End Try
         ' Always disconnect from the SMTP server.
         .Disconnect()
      End With
      '' Set the interface to be normal.
      Cursor.Current = Cursors.Default
      Me.Enabled = True
      ''

   End Sub

   Private Sub Main_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load

      ' Set the connection and authentication information of your TSMTP instance.

      With _tsmtp

         '' Set the proxy server information if necessary.
         ' The host name or IP address of the proxy server.
         '.ProxyHost = "192.168.1.100"
         ' Connection port.
         '.ProxyPort = 1080
         ' Proxy protocol, currently only supports Socks5 - the common SMTP proxy protocol. 
         '.ProxyProtocol = ProxyType.Socks5
         ' User name.
         '.ProxyUser = "myproxyacc"
         ' Password.
         '.ProxyPasswd = "myproxypwd"
         ''

         '' Set the SMTP account information.
         ' MBC: SMTP server.
         .SMTPServer = "smtp.gmail.com"
         ' MBC: SMTP port.
         .SMTPPort = 465
         ' MBC: SMTP account for authentication required SMTP server (most SMTP servers need this).
         .SMTPUser = "[email protected]"
         ' MBC: SMTP password for authentication required SMTP server (most SMTP servers need this).
         .SMTPPasswd = "mypasswd"
         ' MBC: Security connection protocol, if you are not sure, please contact the SMTP provider.
         ' It can be SecureProtocol.None and SecureProtocol.TLS also.
         .Protocol = SecureProtocol.SSL
         ''

      End With
   End Sub
   Private Sub TSMTP_ErrorOccurred(ByVal desc As String) Handles _tsmtp.ErrorOccurred

      ' Display the error messages during sending.

      tbErr.Text = tbErr.Text & vbCrLf & vbCrLf & desc

   End Sub

   Private Sub TSMTP_Progress(ByVal id As Integer, ByVal desc As String) Handles _tsmtp.Progress

      ' Display the progress during sending.

      tbProgress.Text = tbProgress.Text & vbCrLf & vbCrLf & id.ToString & " - " & desc

   End Sub
   Private Sub ComposeEmail()

      ' Compose your message.

      With _tmm

         ' Subject.
         .Subject = "A Test Message Sent by TDNSC"

         ' Not a HTML (rich text) email body (default).
         .IsBodyHtml = False

         ' The eMail content (plain text).
         .Body = "Hi, this is a test message that sent by TSSI .NET SMTP Component."

         '' Add the attachments, if there is no attachment, please do not use this property.
         .Attachments.Clear()
         .Attachments.Add(New FileInfo(New DirectoryInfo(Application.StartupPath).Parent.Parent.FullName & _
                                       "\atts\testatt.txt"))
         .Attachments.Add(New FileInfo(New DirectoryInfo(Application.StartupPath).Parent.Parent.FullName & _
                                       "\atts\testatt.png"))
         ' .Attachments.Add ' Add more...
         ''

         ' MBC: Sender's eMail address.
         .Sender = New MailAddress("[email protected]")

         ' MBC: This value will displayed in message header (From...) of the received email.
         .From = New MailAddress("[email protected]", "From")

         ' MBC: Sets the ReplyTo address for the mail message.
         .ReplyTo = New MailAddress("[email protected]", "ReplyTo")

         ' Whether need a read receipt or not, if do not need, please leave it blank.  
         .Receipt = True

         '' MBC: If _tmm.Receipt property is set as True, 
         '' you can specify a different address than _tmm.From to receive the receipt.
         '' You can also leave _tmm.ReceiptReceiver as blank to use _tmm.From address 
         '' to receive the receipt.
         .ReceiptReceiver = New MailAddress("[email protected]", "RR")
         ''          

         ' Make the virtual eMailing time if necessary. Format: DDD, d MMM YYYY HH:MI:SS.
         ' .SendTime = "Fri, 4 Jul 2014 14:03:08"

         '' Specifies the priority level for the e-mail message. 
         '' Please uncomment one if necessary. 
         ' .Priority = MailPriority.High
         ' .Priority = MailPriority.Low
         ' Normal is the default value, if you have not priority requirement, 
         ' please leave it blank.
         ' .Priority = MailPriority.Normal
         ''

         '''' Add the receivers.
         '' MBC: [To].
         .To.Clear()
         .To.Add(New MailAddress("[email protected]", "You@Gmail"))
         .To.Add(New MailAddress("[email protected]", "You@Hotmail"))
         '.To.Add... ' Add more...
         ''
         '' MBC: [CC].
         .CC.Clear()
         .CC.Add(New MailAddress("[email protected]", "Him@Gmail"))
         .CC.Add(New MailAddress("[email protected]", "Him@Hotmail"))
         '.CC.Add... ' Add more...
         ''
         '' MBC: [BCC].
         .Bcc.Clear()
         .Bcc.Add(New MailAddress("[email protected]", "Her@Gmail"))
         .Bcc.Add(New MailAddress("[email protected]", "Her@Hotmail"))
         '.Bcc.Add... ' Add more...
         ''
         ''''

      End With
   End Sub
End Class

# C# 2008 <Top>

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
/*
 * TSSI .NET SMTP Component Demo (C# 2008)
 * 
 * Note: to test your own SMTP account and the received eMails,
 * you may modify the following code that starts with the "MBC" (may be changed) mark in the comment line.
 * 
 * To read the detailed documentation, please visit
 * https://www.automailsender.com/tssi-dotnet-smtp-component/help.htm
 * 
 * © TriSun Software Inc. All rights reserved.
*/

// Imports TDNSC's namespace first.
using TSSI.eMail;
// Some native members of this namespace will be used in your code.
using System.Net.Mail;
// The third-party open source proxy library.
using Starksoft.Net.Proxy;
// Just for the attachments.
using System.IO;
using Microsoft.VisualBasic;
using System.Windows.Forms;
using System;

namespace TDNSC_Demo_CS_2008 {

   public partial class Main : Form {

      // TSMTP instance (used to send eMail via the (E)SMTP protocol).
      private TSMTP _tsmtp = new TSMTP();
      // TMailMessage instance (the eMail for sending).
      private TMailMessage _tmm = new TMailMessage();

      public Main() {
         InitializeComponent();
      }

      private void Main_Load(object sender, EventArgs e) {

         //// Adds the event handles of _tsmtp.
         _tsmtp.ErrorOccurred +=new TSMTP.ErrorOccurredEventHandler(_tsmtp_ErrorOccurred);
         _tsmtp.Progress +=new TSMTP.ProgressEventHandler(_tsmtp_Progress);
         ////

         ////// Set the connection and authentication information of your TSMTP instance. 

         //// MBC: Set the proxy server information if necessary.
         // The host name or IP address of the proxy server.
         // _tsmtp.ProxyHost = "192.168.1.100";
         // Connection port.
         // _tsmtp.ProxyPort = 1080;
         // Proxy protocol, currently only supports Socks5 - the common SMTP proxy protocol. 
         // _tsmtp.ProxyProtocol = ProxyType.Socks5;
         // User name.
         // _tsmtp.ProxyUser = "myproxyacc";
         // Password.
         // _tsmtp.ProxyPasswd = "myproxypwd";
         ////

         //// Set the SMTP account information.
         // MBC: SMTP server.
         _tsmtp.SMTPServer = "smtp.gmail.com";
         // MBC: SMTP port.
         _tsmtp.SMTPPort = 465;
         // MBC: SMTP account for authentication required SMTP server (most SMTP servers need this).
         _tsmtp.SMTPUser = "[email protected]";         
         // MBC: SMTP password for authentication required SMTP server (most SMTP servers need this).
         _tsmtp.SMTPPasswd = "mypasswd";         
         // MBC: Security connection protocol, if you are not sure, please contact the SMTP provider.
         // It can be SecureProtocol.None and SecureProtocol.TLS also.
         _tsmtp.Protocol = SecureProtocol.SSL;
         ////

         //////
         
      }

      private void _tsmtp_ErrorOccurred(string desc) {

         /* Display the error messages during sending. */       

         tbErr.Text = tbErr.Text + "\r\n\r\n" + desc;

      }

      private void _tsmtp_Progress(int id, string desc) {

         /* Display the progress during sending. */

         tbProgress.Text = tbProgress.Text + "\r\n\r\n" + id + " - " + desc;

      }

      private void ComposeEmail() {

         /* Compose your message. */
      
         // Subject.
         _tmm.Subject = "A Test Message Sent by TDNSC";

         // Not a HTML (rich text) email body (default).
         _tmm.IsBodyHtml = false;

         // The eMail content (plain text).
         _tmm.Body = "Hi, this is a test message that sent by TSSI .NET SMTP Component.";

         //// Add the attachments, if there is no attachment, please do not use this property.
         _tmm.Attachments.Clear();
         _tmm.Attachments.Add(new FileInfo(new DirectoryInfo(Application.StartupPath).Parent.Parent.FullName + 
                                           "\\atts\\testatt.txt"), null, null, null);
         _tmm.Attachments.Add(new FileInfo(new DirectoryInfo(Application.StartupPath).Parent.Parent.FullName + 
                                           "\\atts\\testatt.png"), null, null, null);
         // .Attachments.Add // Add more...
         ////

         // MBC: Sender's eMail address.
         _tmm.Sender = new MailAddress("[email protected]");

         // MBC: This value will displayed in message header (From...) of the received email.
         _tmm.From = new MailAddress("[email protected]", "From");

         // MBC: Sets the ReplyTo address for the mail message.
         _tmm.ReplyTo = new MailAddress("[email protected]", "ReplyTo");         

         // Whether need a read receipt or not, if do not need, please leave it blank.  
         _tmm.Receipt = true;

         //// MBC: If _tmm.Receipt property is set as true, 
         //// you can specify a different address than _tmm.From to receive the receipt.
         //// You can also leave _tmm.ReceiptReceiver as blank to use _tmm.From address 
         //// to receive the receipt.
         _tmm.ReceiptReceiver = new MailAddress("[email protected]", "RR");         
         ////          

         // Make the virtual eMailing time if necessary. Format: DDD, d MMM YYYY HH:MI:SS.
         // _tmm.SendTime = "Fri, 4 Jul 2014 14:03:08";

         //// Specifies the priority level for the e-mail message. 
         //// Please uncomment one if necessary. 
         // _tmm.Priority = MailPriority.High;
         // _tmm.Priority = MailPriority.Low;
         // Normal is the default value, if you have not priority requirement, 
         // please leave it blank.
         // _tmm.Priority = MailPriority.Normal;
         ////

         ////// Add the receivers.
         //// MBC: [To].
         _tmm.To.Clear();
         _tmm.To.Add(new MailAddress("[email protected]", "You@Gmail"));
         _tmm.To.Add(new MailAddress("[email protected]", "You@Hotmail"));
         // _tmm.To.Add... // Add more...
         ////
         //// MBC: [CC].
         _tmm.CC.Clear();
         _tmm.CC.Add(new MailAddress("[email protected]", "Him@Gmail"));
         _tmm.CC.Add(new MailAddress("[email protected]", "Him@Hotmail"));
         // _tmm.CC.Add... // Add more...
         ////
         //// MBC: [BCC].
         _tmm.Bcc.Clear();
         _tmm.Bcc.Add(new MailAddress("[email protected]", "Her@Gmail"));
         _tmm.Bcc.Add(new MailAddress("[email protected]", "Her@Hotmail")); ;
         //// _tmm.Bcc.Add... // Add more...
         //////

      }

      private void bTestLogon_Click(object sender, EventArgs e) {

         /* Test if the given user and password can be used to log on the SMTP server or not. */

         // Initialize the error messages box.
         tbErr.Text = "Error Messages";
         // Initialize the progress box.
         tbProgress.Text = "Progress";         

         //// Set the interface to be busy.
         Cursor.Current = Cursors.WaitCursor;
         this.Enabled = false;
         ////

         try {
            if (_tsmtp.Connect(_tsmtp.SMTPServer, _tsmtp.SMTPPort)) {
               // This utility method is used to test if the given user and 
               // password can be used to log on the SMTP server or not.
               if (_tsmtp.TestLogon()) {
                  Interaction.MsgBox("Connected and logged in to the SMTP server successfully.",
                                     MsgBoxStyle.Information,null);
               }
               else {
                  Interaction.MsgBox("Cannot logged on the SMTP server according to your given information.",
                                     MsgBoxStyle.Exclamation,null);
               }
            }
            else {
               Interaction.MsgBox("Cannot connect to the SMTP server according" + 
                                  " to your given information in your LAN.", 
                                  MsgBoxStyle.Exclamation,null);
            }
         } catch (Exception ex) {
            // Display the exception also.
            tbErr.Text = tbErr.Text + Constants.vbCrLf + ex.Message;               
         }
         // Always disconnect from the SMTP server.
         _tsmtp.Disconnect();

         //// Set the interface to be normal.
         Cursor.Current = Cursors.Default;
         this.Enabled = true;
         ////

      }

      private void bAbout_Click(object sender, EventArgs e) {

         /* Displays the About box, it contains the program and edition information. */
         
         TSMTP.About();

      }

      private void bCheck_Click(object sender, EventArgs e) {

         /* 
          Check the format of an eMail address. 
          TMailMessage.CheckAddress() is a shared method, just call it from the class.
         */

         // The valid one.
         Interaction.MsgBox("[email protected] is " + 
                            (TMailMessage.CheckAddress("[email protected]") ? "valid!" : "invalid!"),
                            MsgBoxStyle.Information,null);

         // The invalid one.
         Interaction.MsgBox("[email protected] is " + 
                            (TMailMessage.CheckAddress("[email protected]") ? "valid!" : "invalid!"), 
                            MsgBoxStyle.Information,null);
      }

      private void bPlain_Click(object sender, EventArgs e) {

         /* Send a plain text message. */

         // Compose your message.
         ComposeEmail();

         ////// Send message.
         // Initialize the error messages box.
         tbErr.Text = "Error Messages";
         // Initialize the progress box.
         tbProgress.Text = "Progress";         
         //// Set the interface to be busy.
         Cursor.Current = Cursors.WaitCursor;
         this.Enabled = false;
         ////
         
         try {
            if (_tsmtp.Connect(_tsmtp.SMTPServer, _tsmtp.SMTPPort)) {
               if (_tsmtp.SendMsg(_tmm)) {
                  Interaction.MsgBox("Sent the plain text message successfully!", 
                                     MsgBoxStyle.Information,null);
               }
               else {
                  Interaction.MsgBox("Failed to send the plain text eMail, please" + 
                                     " see the error messages to know about the reason.", 
                                     MsgBoxStyle.Information,null);
               }
            }
         } catch (Exception ex) {
            // Display the exception also.
            tbErr.Text = tbErr.Text + Constants.vbCrLf + ex.Message;            
         }
         // Always disconnect from the SMTP server.      
         _tsmtp.Disconnect();          
         
         //// Set the interface to be normal.
         Cursor.Current = Cursors.Default;
         this.Enabled = true;
         ////
         //////

      }

      private void bRich_Click(object sender, System.EventArgs e) {

         /* Send a rich text message. */

         //// Compose your message.
         ComposeEmail();
         // Set as HTML (rich text) email body.
         _tmm.IsBodyHtml = true;
         // The eMail content (plain text).
         _tmm.Body = "<html><body><h2>Hi, this is a test message that sent by " +
                     "TSSI .NET SMTP Component.</h2><img src=\"" + 
                     new DirectoryInfo(Application.StartupPath).Parent.Parent.FullName + 
                     "\\atts\\testatt.png\" /></body></html>";
         ////

         ////// Send message.
         // Initialize the error messages box.
         tbErr.Text = "Error Messages";
         // Initialize the progress box.
         tbProgress.Text = "Progress";         
         //// Set the interface to be busy.
         Cursor.Current = Cursors.WaitCursor;
         this.Enabled = false;
         ////
         try {
            if (_tsmtp.Connect(_tsmtp.SMTPServer, _tsmtp.SMTPPort)) {
               if (_tsmtp.SendMsg(_tmm)) {
                  Interaction.MsgBox("Sent the rich text message successfully!", 
                                     MsgBoxStyle.Information, null);
               }
               else {
                  Interaction.MsgBox("Failed to send the rich text eMail, " + 
                                     "please see the error messages to know about the reason.", 
                                     MsgBoxStyle.Information, null);
               }
            }
         } catch (Exception ex) {
            // Display the exception also.
            tbErr.Text = tbErr.Text + Constants.vbCrLf + ex.Message;
            
         }

         // Always disconnect from the SMTP server.
         _tsmtp.Disconnect();            
         
         //// Set the interface to be normal.
         Cursor.Current = Cursors.Default;
         this.Enabled = true;
         ////
         //////

      }	
   }
}

# Demos <Top>

The release package contains two demos, VB 2008 and C# 2008, and all above sample codes are stored in them. To know about how to program with TSSI .NET SMTP Component, just download the release package of TSSI .NET SMTP Component Trial Edition, and then extract all files to your local disk to learn.
How to Distribute Your Application
It is very easy to distribute your application with TSSI .NET SMTP Component, just include the following files in your installer / deployment package and deploy them to the same folder of your application.
  • TSSI .NET SMTP Component.dll - TSSI .NET SMTP library for enabling your application with the (E)SMTP based emailing feature.
  • Starksoft.Net.Proxy.dll - an open source .NET library for enabling your application with the Socks5 proxy feature.
Thankfully, they are very very small: only 63 KB, if your installer has the compression feature, they only occupy extra 24 KB in your installer.
Folders & Files (in TDNSC's Release Package) Explanation
  • tdnsc.zip - TSSI .NET SMTP Component's release package.
    • helper.html - product information, support and other useful information on the web.
    • license-agreement.txt - TSSI .NET SMTP Component license agreement.
    • new-version-checker.html - used to check the new version.
    • readme.txt - the first file you should read after downloaded.
    • libs (folder) - the .NET assemblies of TDNSC that used to distribute your applications as above.
    • demos (folder) - the demos that written by VB 2008 and C# 2008 for your reference as above.
How to Upgrade Product Version
1. Open "new-version-checker.html" file in the downloaded package (tdnsc.zip).
2. Download the latest version of this product from our official website if the new version is available.
3. Extract all files from tdnsc.zip to replace your old files.

Download v2.0 for .NET Framework, 125 KB Download