How does System.Net.Mail.SMTPClient do its local IP binding에 제공된 것과 비슷한 코드를 따르려고합니다. 여러 IP 주소가있는 컴퓨터에서 Windows 7 및 .Net 4.0을 사용하고 있습니다. 나는ServicePointManager를 재설정 할 수 있습니까?
private static IPEndPoint BindIPEndPointCallback(ServicePoint servicePoint, IPEndPoint remoteEndPoint, int retryCount)
{
string IPAddr = //some logic to return a different IP each time
return new IPEndPoint(IPAddr, 0);
}
내가 다음
SmtpClient client = new SmtpClient();
client.Host = SMTP_SERVER; //IP Address as string
client.Port = 25;
client.EnableSsl = false;
client.ServicePoint.BindIPEndPointDelegate
= new System.Net.BindIPEndPoint(BindIPEndPointCallback);
client.ServicePoint.ConnectionLeaseTimeout = 0;
client.Send(msg); //msg is of type MailMessage properly initialized/set
client = null;
이 코드가 호출되는 첫 번째 시간을 사용하여 내 이메일을 보내 정의 대리자가 호출됩니다 및 어떤 IP 주소가 설정됩니다 BindIPEndPointDelegate,이 사용됩니다있다. 다음 번에이 코드가 호출되면 대리자는 결코 으로 호출되지 않습니다. 즉 첫 번째 IP 주소가 이후에 사용됩니다. 코드가 호출 될 때마다 위임 콜백이 호출되는 상황을 변경할 수 있습니까?
ServicePointManager (정적 클래스)이 대리자에 대한 첫 번째 호출의 결과를 캐시하고 있다고 생각합니다. 이 클래스를 재설정 할 수 있습니까? 나는 성능에 신경 쓰지 않는다.
는 O. O.
smtp 클라이언트를 사용하여 랩핑하고 사용할 수 있습니다. '(var client = new SmtpClient())를 사용하여 {client.Send (msg); }' –