SmtpClient.BindEndPoint Property


Gets or sets the local IP address binding for sending email.

[Visual Basic]
Public Property BindEndPoint As System.NET.EndPoint
[C#]
public System.NET.EndPoint BindEndPoint {get; set;}
[C++]
public: __property System.NET.EndPoint^ get_BindEndPoint();
public: __property void set_BindEndPoint(System.NET.EndPoint^);
[JScript]
public function get BindEndPoint() : System.NET.EndPoint;
public function set BindEndPoint(System.NET.EndPoint);

Property Value

A valid IP address network endpoint.

Remarks

By default, SmtpClient uses the default IP address of current machine to send email. However, if there are mulitple IP addresses on current machine, you can specify one of IP address to bind and send the email.

Example

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

[VB - Send Email with IP address binding]
Imports EASendMail
Imports System.Net
Sub SendMail()
    Dim oMail As SmtpMail = New SmtpMail("TryIt")
    Dim oSmtp As SmtpClient = New SmtpClient

    Try
        Dim oServer As SmtpServer = New SmtpServer("myserveraddress")
        
        oMail.From = New MailAddress("from@adminsystem.com")
        oMail.To.Add(New MailAddress("to@adminsystem.com"))
        
        oMail.Subject = "test subject"
        oMail.TextBody = "test email with IP binding"
        oSmtp.BindEndPoint = New IPEndPoint(IPAddress.Parse("192.168.0.1"), 0 )
        oSmtp.SendMail( oServer, oMail )
        Console.WriteLine( "message was sent" )
        
    Catch exp As SmtpTerminatedException
        Console.WriteLine(exp.Message)
    Catch exp As SmtpServerException
        Console.WriteLine("Exception: Server Respond: {0}", exp.ErrorMessage)
    Catch exp As System.Net.Sockets.SocketException
        Console.WriteLine("Exception: Networking Error: {0} {1}", exp.ErrorCode, exp.Message)
    Catch exp As System.ComponentModel.Win32Exception
        Console.WriteLine("Exception: System Error: {0} {1}", exp.ErrorCode, exp.Message)
    Catch exp As System.Exception
        Console.WriteLine("Exception: Common: {0}", exp.Message)
    End Try

    Console.WriteLine("SMTP LOG:" & vbCrLf)
    Console.WriteLine(oSmtp.SmtpConversation)
End Sub