首页 > C#,使用System.Net.Mail.SmtpClient 如何指定使用哪个本地IP地址?

C#,使用System.Net.Mail.SmtpClient 如何指定使用哪个本地IP地址?

如题,本地有多个IP地址,如何使用不同的IP地址发送邮件,没看到相应的API


使用 SmtpClient.ServicePoint.BindIPEndPointDelegate

http://msdn.microsoft.com/en-us/library/system.net.servicepoint.bindipendpointdelegate.aspx

var smtpClient = new SmtpClient(...);
smtpClient.ServicePoint.BindIPEndPointDelegate = (servicePoint, remoteEndPoint, retryCount) =>
  new IPEndPoint( IPAddress.Parse( "YOUR LOCAL ADDRESS" ), 0 );
【热门文章】
【热门文章】