Provides properties and methods for constructing an e-mail header.
System.Object
EASendMail.HeaderItem
[Visual Basic] Public Class HeaderItem
[C#] public class HeaderItem
[C++] public ref class HeaderItem
[JScript] public class HeaderItem
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Public Constructors
HeaderItem Constructor | Initializes a new instance of the HeaderItem class. |
Public Properties
HeaderKey | Gets or sets the key of the header. |
HeaderValue | Gets or sets the value of the header. |
Example
[Visual Basic, C#] To get the full samples of EASendMail, please refer to Samples section.
[VB - Add customized header] Imports EASendMail Public Sub SendMail(sender As String, toRecipients As String, ccRecipients As String, subject As String, bodyText As String, server As String, user As String, password As String, useSsl As Boolean) Try Dim oMail As SmtpMail = New SmtpMail("TryIt") ' inserts a auto-submitted header to indicate that ' the message was originated by an automatic process, or an automatic ' responder, rather than by a human oMail.Headers.Insert(0, new HeaderItem( "auto-submitted", "auto-generated")) oMail.From = New MailAddress(sender) oMail.To = New AddressCollection(toRecipients) oMail.Cc = New AddressCollection(ccRecipients) oMail.Subject = subject ' If bodyText contains html tags, please use ' oMail.HtmlBody = bodyText oMail.TextBody = bodyText ' Add attachment ' oMail.AddAttachment("c:\test.gif") ' Set server address Dim oServer As SmtpServer = New SmtpServer(server) If user.Length > 0 And password.Length > 0 Then ' Set user/password for ESMTP authentication oServer.User = user oServer.Password = password End If ' Most mordern SMTP servers require SSL/TLS connection now. ' ConnectTryTLS means if server supports SSL/TLS, SSL/TLS will be used automatically. oServer.ConnectType = If(useSsl, SmtpConnectType.ConnectSSLAuto, SmtpConnectType.ConnectTryTLS) Dim oSmtp As SmtpClient = New SmtpClient() ' To generate a log file for SMTP transaction, please use ' oSmtp.LogFileName = "c:\smtp.txt" oSmtp.SendMail(oServer, oMail) Console.WriteLine("The message has been submitted to server successfully!") Catch ex As Exception Console.WriteLine("Exception: {0}", ex.Message) End Try End Sub
[C# - Add customized header] using System; using System.Collections; using EASendMail; public static void SendMail(string sender, string toRecipients, string ccRecipients, string subject, string bodyText, string server, string user, string password, bool useSsl) { try { SmtpMail oMail = new SmtpMail("TryIt"); // inserts a auto-submitted header to indicate that // the message was originated by an automatic process, or an automatic // responder, rather than by a human oMail.Headers.Insert(0, new HeaderItem( "auto-submitted", "auto-generated")); oMail.From = sender; oMail.To = toRecipients; oMail.Cc = ccRecipients; oMail.Subject = subject; // If bodyText contains the html tags, please use // oMail.HtmlBody = bodyText; oMail.TextBody = bodyText; // Add attachment // oMail.AddAttachment("c:\\test.gif"); // Set server address SmtpServer oServer = new SmtpServer(server); if (user.Length != 0 && password.Length != 0) { // Set user/password for ESMTP authentication oServer.User = user; oServer.Password = password; } // Most mordern SMTP servers require SSL/TLS connection now. // ConnectTryTLS means if server supports SSL/TLS, SSL/TLS will be used automatically. oServer.ConnectType = (useSsl) ? SmtpConnectType.ConnectSSLAuto : SmtpConnectType.ConnectTryTLS; SmtpClient oSmtp = new SmtpClient(); // To generate a log file for SMTP transaction, please use // oSmtp.LogFileName = "c:\\smtp.txt"; oSmtp.SendMail(oServer, oMail); Console.WriteLine("The message has been submitted to server successfully!"); } catch (Exception exp) { Console.WriteLine("Exception: {0}", exp.Message); } }