Dart.Mail Namespace : Smtp Class |
The Smtp component sends Internet mail. It is feature-rich and flexible, and includes functionality not found in the .NET Platform such as multiple authentication techniques, proxy support, Stream support, access to the TCP connection, debugging features and more.
A short description of common usage follows. See the "Code Examples" topic for examples in C# and VB.
Session Management: Authentication is automatic. Close terminates the connection.
Sends Basic Mail: Send(String,String,String,String) provides a high-level method to send mail with one line of code.
Sends Advanced Mail: Send(MailMessage) encodes and sends the referenced MailMessage, allowing unprecedented ability to create any email message, no matter how complex the structure!
Sends Encoded Mail: Send(Stream,String,String) sends previously encoded email.
"On-the-fly" encoding: All MailMessage parts are encoded on-the-fly and streamed to the socket, minimizing the memory/disk footprint.
Displaying Progress: Progress provides progress updates while uploading.
Viewing SMTP Protocol Communications: The Smtp.Connection.Log event provides access to all commands and data sent over the TCP connection.
Control connection: Connection exposes the TCP connection, allowing access to low-level properties and methods. Can be used to view TCP-level properties, such as the local and remote IP address.
Sending commands: Any command (including proprietary commands) can be sent/received using Connection.Write() and Connection.Read().
private void sendMail(object sender) { //Create message to send MailMessage message = new MailMessage(); message.To = toAddress; message.From = fromAddress; message.Subject = "File Attached"; message.Text = "Please see the attached file."; //Add the attachment message.Attachments.Add(new Attachment(Application.StartupPath + "\\myImage.jpg")); //Set session parameters smtp1.Session.RemoteEndPoint = new Dart.Mail.IPEndPoint(myMailServer, Smtp.GetDefaultPort(smtp1.Session)); smtp1.Session.Username = myUsername; smtp1.Session.Password = myPassword; //Send message smtp1.Send(message); //Logout gracefully smtp1.Close(); } private void smtp1_Progress(object sender, SmtpProgressEventArgs e) { //Update progress bar as message is sent progressBar1.Value = (e.Final) ? 0 : (int)((e.Position * 100) / e.Length); }
Private Sub sendMail(ByVal sender As Object) 'Create message to send Dim message As New MailMessage() message.To = toAddress message.From = fromAddress message.Subject = "File Attached" message.Text = "Please see the attached file." 'Add the attachment message.Attachments.Add(New Attachment(Application.StartupPath & "\myImage.jpg")) 'Set session parameters smtp1.Session.RemoteEndPoint = New Dart.Mail.IPEndPoint(myMailServer, Smtp.GetDefaultPort(smtp1.Session)) smtp1.Session.Username = myUsername smtp1.Session.Password = myPassword 'Send message smtp1.Send(message) 'Logout gracefully smtp1.Close() End Sub Private Sub smtp1_Progress(ByVal sender As Object, ByVal e As SmtpProgressEventArgs) Handles smtp1.Progress 'Update progress bar as message is sent progressBar1.Value = If(e.Final, 0, CInt((e.Position * 100) \ e.Length)) End Sub
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
Dart.Mail.ComponentBase
Dart.Mail.MailBase
Dart.Mail.Smtp