SmtpClient.DnsServerIP Property


Gets or sets the log file name for smtp transaction.

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

Property Value

A valid IPv4 address of dns server.

Remarks

By default, SmtpClient uses the default dns server of current machine. The dns server is used to query the MX records of recipient. To learn more detail, please refer to: Send E-mail Directly (Simulating SMTP server).

Example

[Visual Basic, C#, C++, JScript.NET] The following example demonstrates how to send email with EASendMail SMTP Component directly, but it doesn't demonstrates the events usage. To get the full samples of EASendMail, please refer to Samples section.

[VB - Send Email - MX Lookup]
Imports EASendMail

Public Sub SendMail( sFrom As String, _ 
    sTo As String, _ 
    sSubject As String, _
    sBodyText As String )

    Dim oMail As SmtpMail = New SmtpMail("TryIt")
    Dim oSmtp As SmtpClient = New SmtpClient
    'To generate a log file for SMTP transaction, please use 
    'oSmtp.LogFileName = "c:\smtp.log"

    Dim errStr As String = ""

    Try
        oMail.From = New MailAddress( sFrom )
        'Only specify an email address in sTo. For multiple addresses, please refer to 
        'EASendMail full samples.
        oMail.To = New AddressCollection(sTo) 
      
        oMail.Subject = sSubject
        oMail.TextBody = sBodyText
        'EASendMail will send email directly if no server address is specified
        Dim oServer As SmtpServer = New SmtpServer("")

        'To send email to recipient directly (simulating the smtp server),
        'please add a Received header, 
        'otherwise, many anti-spam filter will mark it as junk email.    
        
        Dim cur As System.Globalization.CultureInfo = New System.Globalization.CultureInfo("en-U")
        Dim gmtdate As String = System.DateTime.Now.ToString("ddd, dd MMM yyyy HH:mm:ss zz00", cur)
        Dim recvheader As String = String.Format("from {0} ([127.0.0.1]) by {0} ([127.0.0.1]) with SMTPSVC;" & vbCrLf & Chr(9) & " {1}", _
                    oServer.HeloDomain, _
                    gmtdate)
        oMail.Headers.Insert(0, New HeaderItem("Received", recvheader)) 
        
        ' using google public DNS server
        oSmtp.DnsServerIP = "8.8.8.8"

        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# - Send Email - MX Lookup]
using System;
using System.Collections;
using EASendMail;

public void SendMail( string sFrom, 
    string sTo, 
    string sSubject,
    string sBodyText )
{
    SmtpMail oMail = new SmtpMail("TryIt");
    SmtpClient oSmtp = new SmtpClient();
    //To generate a log file for SMTP transaction, please use 
    //oSmtp.LogFileName = "c:\\smtp.log";
    string err = "";

    try
    {
        oMail.From = sFrom;
        //Only specify an email address in sTo. For multiple addresses, please refer to 
        //EASendMail full samples. 
        oMail.To = sTo;
     
        oMail.Subject = sSubject;
        oMail.TextBody = sBodyText;
        //EASendMail will send email directly if no server address is specified       
        SmtpServer oServer = new SmtpServer( "" );
        
        //To send email to recipient directly (simulating smtp server),
        //please add a Received header, 
        //otherwise, many anti-spam filter will mark it as junk email.
        System.Globalization.CultureInfo cur = new System.Globalization.CultureInfo("en-U");
        string gmtdate = System.DateTime.Now.ToString("ddd, dd MMM yyyy HH:mm:ss zz00", cur);
        string recvheader = String.Format( "from {0} ([127.0.0.1]) by {0} ([127.0.0.1]) with SMTPSVC;\r\n\t {1}",
                            oServer.HeloDomain,
                            gmtdate );

        oMail.Headers.Insert( 0, new HeaderItem( "Received", recvheader ));    
        
        // using google public DNS server
        oSmtp.DnsServerIP = "8.8.8.8";
                    
        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 );
    }
}

[C++/CLI - Send Email - MX Lookup]
using namespace System;
using namespace System::Collections;
using namespace EASendMail; 

System::Void SendMail( System::String ^sFrom, 
    System::String ^sTo, 
    System::String ^sSubject,
    System::String ^sBodyText )
{
    SmtpMail ^oMail = gcnew SmtpMail("TryIt");
    SmtpClient ^oSmtp = gcnew SmtpClient();
    //To generate a log file for SMTP transaction, please use 
    //oSmtp->LogFileName = "c:\\smtp.log";

    System::String ^err = "";

    try
    {
        oMail->From = gcnew EASendMail::MailAddress(sFrom);
        //Only specify an email address in sTo. For multiple addresses, please refer to 
        //EASendMail full samples.
        oMail->To =  gcnew EASendMail::AddressCollection(sTo);
        oMail->Subject = sSubject;
        oMail->TextBody = sBodyText;
        //EASendMail will send email directly if no server address is specified                
        SmtpServer ^oServer = gcnew SmtpServer( "" ); 
        
        //To send email to recipient directly (simulating the smtp server),
        //please add a Received header, 
        //otherwise, many anti-spam filter will mark it as junk email.
        System::Globalization::CultureInfo ^cur = gcnew System::Globalization::CultureInfo("en-U");
        System::DateTime now = System::DateTime::Now;
        System::String ^gmtdate = now.ToString("ddd, dd MMM yyyy HH:mm:ss zz00", cur);
        System::String ^recvheader = String::Format( "from {0} ([127.0.0.1]) by {0} ([127.0.0.1]) with SMTPSVC;\r\n\t {1}",
            oServer->HeloDomain,
            gmtdate );

        oMail->Headers->Insert( 0, gcnew HeaderItem( "Received", recvheader ));
                           
        // using google public DNS server
        oSmtp->DnsServerIP = "8.8.8.8";

        oSmtp->SendMail( oServer, oMail );
    
        MessageBox::Show( String::Format( "The message was sent to {0} successfully!", 
            oSmtp->CurrentSmtpServer->Server ));

    }
    catch( EASendMail::SmtpTerminatedException ^exp )
    {
        err = exp->Message;
    }
    catch( EASendMail::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.ToString("d"), exp->Message );
    }
    catch( System::ComponentModel::Win32Exception ^exp )
    {
        err = String::Format( "Exception: System Error: {0} {1}", exp->ErrorCode.ToString("d"), exp->Message );           
    }
    catch( System::Exception ^exp )
    {
        err = String::Format( "Exception: Common: {0}", exp->Message );            
    }
    
    if( err->Length > 0  )
    {
        MessageBox::Show( err );
    }
}

[JScript.NET - Send Email - MX Lookup]
public function SendMail( sFrom:String, 
    sTo:String, 
    sSubject:String,
    sBodyText:String )
{
    var oMail:SmtpMail =  new SmtpMail("TryIt");
    var oSmtp:SmtpClient = new SmtpClient();
    //To generate a log file for SMTP transaction, please use 
    //oSmtp.LogFileName = "c:\\smtp.log";
        
    var err:String = "";    
    try
    {           
        oMail.From  = new MailAddress(sFrom);
        oMail.Subject = sSubject
        //Only specify an email address in sTo. For multiple addresses, please refer to 
        //EASendMail full samples.
             
        oMail.To = new AddressCollection(sTo);
        oMail.TextBody = sBodyText;
        //EASendMail will send email directly if no server address is specified         
        var oServer:SmtpServer = new SmtpServer("");
        
        //To send email to recipient directly (simulating the smtp server),
        //please add a Received header, 
        //otherwise, many anti-spam filter will mark it as junk email.  
        var cur:System.Globalization.CultureInfo = new System.Globalization.CultureInfo("en-U");
        var gmtdate:String = System.DateTime.Now.ToString("ddd, dd MMM yyyy HH:mm:ss zz00", cur);
        var recvheader:String = String.Format( "from {0} ([127.0.0.1]) by {0} ([127.0.0.1]) with SMTPSVC;\r\n\t {1}",
                            oServer.HeloDomain,
                            gmtdate );

        // using google public DNS server
        oSmtp.DnsServerIP = "8.8.8.8";

        oMail.Headers.Insert( 0, new HeaderItem( "Received", recvheader ));       
        oSmtp.SendMail( oServer, oMail );
        MessageBox.Show( String.Format("The message was sent to {0} successfully!", oServer.Server ));
        
    }
    catch( exp:SmtpTerminatedException  )
    {
        err = exp.Message;
    }
    catch( exp:SmtpServerException )
    {
        err = String.Format( "Exception: Server Respond: {0}", exp.ErrorMessage );
    }
    catch( exp:System.Net.Sockets.SocketException )
    {
        err = String.Format( "Exception: Networking Error: {0} {1}", exp.ErrorCode, exp.Message );
    }
    catch( exp:System.ComponentModel.Win32Exception )
    {
        err = String.Format( "Exception: System Error: {0} {1}", exp.ErrorCode, exp.Message );          
    }
    catch( exp:System.Exception )
    {
        err = String.Format( "Exception: Common: {0}", exp.Message );           
    }   
    
    if( err.Length > 0 )
    {
        MesageBox.Show( err );
    }
}