HeaderItem.HeaderValue Property


Gets or sets the value of the header.

[Visual Basic]
Public Property HeaderValue As String
[C#]
public string HeaderValue {get; set;}
[C++]
public: __property String^ get_HeaderValue();
public: __property void set_HeaderValue(String^);
[JScript]
public function get HeaderValue() : String;
public function set HeaderValue(String);

Property Value

A String value indicating the value of the HeaderItem.

Example

[Visual Basic, C#] To get the full samples of EASendMail, please refer to Samples section.

[VB - Add customized email header]
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 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" ))
        ' you can also use the following code
        ' oMail.Headers.Insert( 0, new HeaderItem( "auto-submitted: auto-generated" ));        
        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# - Add customized email header]
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 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" ));
        //you can also use the following code
        //oMail.Headers.Insert( 0, new HeaderItem( "auto-submitted: auto-generated" ));
        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 );
    }
}