Initializes a new instance of the HeaderItem class.
[VisualĀ Basic]
Public Sub New(
headerKey As String, _
headerValue As String _
)
Public Sub New( _
keyvalue As String _
)
[C#]
public HeaderItem(
string headerKey,
string headerValue
);
public HeaderItem(
string keyvalue
);
[C++]
public: HeaderItem(
String* headerKey,
String* headerValue
);
public: HeaderItem(
String* keyvalue
);
[JScript]
public function HeaderItem(
headerKey : String,
headerValue : String
);
public function HeaderItem(
keyvalue : String
);
Parameters
Example
[Visual Basic, C#] To get the full samples of EASendMail, please refer to Samples section.
[Visual Basic]
Imports EASendMail
Public Sub SendMail( sFrom As String, _
sTo As String, _
sCc As String, _
sServer As String, _
sUserName As String, _
sPassword As String, _
sSubject As String, _
sBodyText As String, _
bSSLConnection As Boolean )
Dim oMail As SmtpMail = New SmtpMail("TryIt")
Dim oSmtp As SmtpClient = New SmtpClient
Dim errStr As String = ""
Try
'inserts a reply-to header, then the email will be replied to this address instead of From
oMail.Headers.Insert( 0, new HeaderItem( "Reply-To", "reply@adminsystem.com" ))
//you can also use the following code
//oMail.Headers.Insert( 0, new HeaderItem( "Reply-To: reply@adminsystem.com" ));
oMail.From = New MailAddress( sFrom )
oMail.To = New AddressCollection(sTo)
oMail.Cc = New AddressCollection(sCc)
oMail.Subject = sSubject
oMail.TextBody = sBodyText
Dim oServer As SmtpServer = New SmtpServer(sServer)
If sUserName.Length > 0 And sPassword.Length > 0 Then
oServer.User = sUserName
oServer.Password = sPassword
End If
If (bSSLConnection) Then
oServer.ConnectType = SmtpConnectType.ConnectSSLAuto
End If
oSmtp.SendMail(oServer, oMail)
MessageBox.Show(String.Format("The message was sent to {0} successfully!", _
oSmtp.CurrentSmtpServer.Server))
Catch exp As SmtpTerminatedException
errStr = exp.Message
Catch exp As SmtpServerException
errStr = String.Format("Exception: Server Respond: {0}", exp.ErrorMessage)
Catch exp As System.Net.Sockets.SocketException
errStr = String.Format("Exception: Networking Error: {0} {1}", exp.ErrorCode, exp.Message)
Catch exp As System.ComponentModel.Win32Exception
errStr = String.Format("Exception: System Error: {0} {1}", exp.ErrorCode, exp.Message)
Catch exp As System.Exception
errStr = String.Format("Exception: Common: {0}", exp.Message)
End Try
If errStr.Length > 0 Then
MessageBox.Show(errStr)
End If
End Sub
[C#]
using System;
using System.Collections;
using EASendMail;
public void SendMail( string sFrom,
string sTo,
string sCc,
string sServer,
string sUserName,
string sPassword,
string sSubject,
string sBodyText,
bool bSSLConnection )
{
SmtpMail oMail = new SmtpMail("TryIt");
SmtpClient oSmtp = new SmtpClient();
string err = "";
try
{
//inserts a reply-to header, then the email will be replied to this address instead of From
oMail.Headers.Insert( 0, new HeaderItem( "Reply-To", "reply@adminsystem.com" ));
//you can also use the following code
//oMail.Headers.Insert( 0, new HeaderItem( "Reply-To: reply@adminsystem.com" ));
oMail.From = sFrom;
oMail.To = sTo;
oMail.Cc = sCc;
oMail.Subject = sSubject;
oMail.TextBody = sBodyText;
SmtpServer oServer = new SmtpServer( sServer );
if( sUserName.Length != 0 && sPassword.Length != 0 )
{
oServer.User = sUserName;
oServer.Password = sPassword;
}
if( bSSLConnection )
oServer.ConnectType = SmtpConnectType.ConnectSSLAuto;
oSmtp.SendMail( oServer, oMail );
MessageBox.Show( String.Format( "The message was sent to {0} successfully!",
oSmtp.CurrentSmtpServer.Server ));
}
catch( SmtpTerminatedException exp )
{
err = exp.Message;
}
catch( SmtpServerException exp )
{
err = String.Format( "Exception: Server Respond: {0}", exp.ErrorMessage );
}
catch( System.Net.Sockets.SocketException exp )
{
err = String.Format( "Exception: Networking Error: {0} {1}", exp.ErrorCode, exp.Message );
}
catch( System.ComponentModel.Win32Exception exp )
{
err = String.Format( "Exception: System Error: {0} {1}", exp.ErrorCode, exp.Message );
}
catch( System.Exception exp )
{
err = String.Format( "Exception: Common: {0}", exp.Message );
}
if( err.Length > 0 )
{
MessageBox.Show( err );
}
}