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


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

smtp c# email

冰冷的雨季 11 years, 8 months ago

使用 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 );

纯洁的腐女 answered 11 years, 8 months ago

Your Answer