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++] 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 SendMailWithMxRecord(sender As String,
    recipient As String,
    subject As String,
    bodyText As String)

    Try
        Dim oMail As SmtpMail = New SmtpMail("TryIt")

        oMail.From = New MailAddress(sender)
        ' Only specify an email address in recipient. For multiple addresses, please send it one by one.
        oMail.To = New AddressCollection(recipient)

        oMail.Subject = subject
        oMail.TextBody = bodyText

        ' The email will be sent to recipient server 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 as SMTP trace time stamp
        Dim gmtDateTime As String = DateTime.Now.ToString("ddd, dd MMM yyyy HH:mm:ss zz00", 
                                                New System.Globalization.CultureInfo("en-US"))
        Dim receivedHeader As String = String.Format("from {0} ([127.0.0.1]) by {0} ([127.0.0.1]) with SMTPSVC;" & vbCrLf & Chr(9) & " {1}",
                oServer.HeloDomain,
                gmtDateTime)

        oMail.Headers.Insert(0, New HeaderItem("Received", receivedHeader))

        Dim oSmtp As SmtpClient = New SmtpClient()

        ' To generate a log file for SMTP transaction, please use 
        ' oSmtp.LogFileName = "c:\smtp.txt"

        ' use google public DNS server
        oSmtp.DnsServerIP = "8.8.8.8"

        oSmtp.SendMail(oServer, oMail)
        Console.WriteLine("The message was sent to {0} successfully!", oSmtp.CurrentSmtpServer.Server)

    Catch ex As Exception
        Console.WriteLine("Exception: {0}", ex.Message)
    End Try

End Sub


[C# - Send Email - MX Lookup] using System; using System.Collections; using EASendMail; public void SendMailWithMxRecord(string sender, string recipient, string subject, string bodyText) { try { SmtpMail oMail = new SmtpMail("TryIt"); oMail.From = sender; // Only specify an email address in recipient. For multiple addresses, please send it one by one. oMail.To = recipient; oMail.Subject = subject; oMail.TextBody = bodyText; // The email will be sent to recipient server 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 as SMTP trace time stamp string gmtDateTime = DateTime.Now.ToString("ddd, dd MMM yyyy HH:mm:ss zz00", new System.Globalization.CultureInfo("en-US")); string recvheader = string.Format("from {0} ([127.0.0.1]) by {0} ([127.0.0.1]) with SMTPSVC;\r\n\t {1}", oServer.HeloDomain, gmtDateTime); oMail.Headers.Insert(0, new HeaderItem("Received", recvheader)); SmtpClient oSmtp = new SmtpClient(); // To generate a log file for SMTP transaction, please use // oSmtp.LogFileName = "c:\\smtp.txt"; // use google public DNS server oSmtp.DnsServerIP = "8.8.8.8"; oSmtp.SendMail(oServer, oMail); Console.WriteLine("The message was sent to {0} successfully!", oSmtp.CurrentSmtpServer.Server); } catch (Exception exp) { Console.WriteLine("Exception: {0}", exp.Message); } }
[C++/CLI - Send Email - MX Lookup] using namespace System; using namespace System::Collections; using namespace EASendMail; void SendMailWithMxRecord(String ^sender, String ^recipient, String ^subject, String ^bodyText) { try { SmtpMail ^oMail = gcnew SmtpMail("TryIt"); oMail->From = gcnew EASendMail::MailAddress(sender); // Only specify an email address in sTo. For multiple addresses, please send it one by one oMail->To = gcnew EASendMail::AddressCollection(recipient); oMail->Subject = subject; oMail->TextBody = bodyText; // The email will be sent to recipient server 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 as SMTP trace time stamp String ^gmtDateTime = DateTime::Now.ToString("ddd, dd MMM yyyy HH:mm:ss zz00", gcnew System::Globalization::CultureInfo("en-US")); String ^receivedHeader = String::Format("from {0} ([127.0.0.1]) by {0} ([127.0.0.1]) with SMTPSVC;\r\n\t {1}", oServer->HeloDomain, gmtDateTime); oMail->Headers->Insert(0, gcnew HeaderItem("Received", receivedHeader)); SmtpClient ^oSmtp = gcnew SmtpClient(); // To generate a log file for SMTP transaction, please use // oSmtp->LogFileName = "c:\\smtp.txt"; // use google public DNS server oSmtp->DnsServerIP = "8.8.8.8"; oSmtp->SendMail(oServer, oMail); Console::WriteLine("The message was sent to {0} successfully!", oSmtp->CurrentSmtpServer->Server); } catch (Exception ^exp) { Console::WriteLine("Exception: {0}", exp->Message); } }