How to use a proxy?
diudiu1 opened this issue · comments
https://stackoverflow.com/questions/844835/sending-mail-through-http-proxy
I found a way to use a proxy from this answer, but the email was not sent successfully after I used it. I'm sure my proxy address is correct because my http proxy for another service also uses this address;
using (var client = new SmtpClient())
{
if (!string.IsNullOrWhiteSpace(proxyUrl))
{
if (proxyUrl.IndexOf("://") == -1)
{
proxyUrl = "http://" + proxyUrl;
}
var uri= new Uri(proxyUrl);
client.ProxyClient = new HttpProxyClient(uri.Host, uri.Port);
}
await client.ConnectAsync(mailServer, mailServerPort, SecureSocketOptions.None);
await client.AuthenticateAsync(sendAccount, sendPassword);
await client.SendAsync(message);
await client.DisconnectAsync(true);
}