我可以通过以下方式通过Yahoo电子邮件发送电子邮件。但我的问题是,我是否可以使计算机在连接雅虎服务器时使用代理?我的意思是使用代理连接来连接雅虎smpt服务器。这可能吗 ?谢谢
public static bool func_SendEmail(string srFrom, string srSenderEmail, string srSenderEmailPw,
string srHtmlBody, string srTextBody, string srTitle, string srProxy)
{
try
{
using (MailMessage message = new MailMessage(new MailAddress(srSenderEmail, srFrom), new MailAddress(srSenderEmail)))
{
message.ReplyTo = new MailAddress(srSenderEmail, srFrom);
message.IsBodyHtml = false;
message.Subject = srTitle;
message.SubjectEncoding = System.Text.Encoding.UTF8;
AlternateView textPart = AlternateView.CreateAlternateViewFromString(srTextBody, Encoding.UTF8, "text/plain");
textPart.TransferEncoding = System.Net.Mime.TransferEncoding.QuotedPrintable;
message.AlternateViews.Add(textPart);
AlternateView htmlPart = AlternateView.CreateAlternateViewFromString(srHtmlBody, Encoding.UTF8, "text/html");
htmlPart.TransferEncoding = System.Net.Mime.TransferEncoding.QuotedPrintable;
message.AlternateViews.Add(htmlPart);
message.BodyEncoding = Encoding.UTF8;
using (SmtpClient oSmtp = new SmtpClient())
{
oSmtp.Host = "smtp.mail.yahoo.com";
oSmtp.Credentials = new NetworkCredential(srSenderEmail, srSenderEmailPw);
oSmtp.EnableSsl = false;
oSmtp.Port = 587;
oSmtp.Send(message);
}
}
}
catch
{
return false;
}
return true;
}
好的,这个问题和这个问题不一样:Sending mail through http proxy
该问题专门询问如何使用代理
我的问题另一方面询问如何使用http代理连接另一个邮件服务器来发送电子邮件
在这种情况下,我想使用线程,每个线程的代理,并从此每个线程连接到雅虎smtp服务器使用http代理发送电子邮件
谢谢
答案 0 :(得分:2)
System.Net.GlobalProxySelection.Select = new WebProxy(address,port);
System.Net.GlobalProxySelection.Select
已被弃用如果您使用它,您将收到警告:
此类已被弃用。请使用WebRequest.DefaultWebProxy 而是访问和设置全局默认代理。请改用“null” GetEmptyWebProxy。 http://go.microsoft.com/fwlink/?linkid=14202
请改用:
WebRequest.DefaultWebProxy = new WebProxy(address,port);