如何在C#中通过代理服务器发送电子邮件
问题描述:
我想使用ASP.NET发送邮件,
但我想通过代理服务器发送电子邮件,
那么,我应该如何编辑下面的代码以通过代理服务器发送代码?
谢谢
Hi I want to send mail with ASP.NET,
but I want to send email through proxy server,
So how should I edit the code below to send it through a proxy server?
Thanks
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient(ConfigurationManager.AppSettings["MailServer"]);
mail.From = new MailAddress(ConfigurationManager.AppSettings["MailAccount"]);
mail.To.Add(toAddres);
mail.CC.Add(new MailAddress(ccAddress));
mail.Subject = subject;
mail.Body = content;
mail.IsBodyHtml = true;
SmtpServer.Port = ConfigurationManager.AppSettings["MailPort"] == null ? 587 : int.Parse(ConfigurationManager.AppSettings["MailPort"]);
SmtpServer.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["MailUserName"], ConfigurationManager.AppSettings["MailPassword"]);
SmtpServer.EnableSsl = false;
SmtpServer.Send(mail);
答
您可以创建方法来通过代理发送邮件...
You can create a Method to send the mail through proxy...
MailAddress from = new MailAddress("from@mailserver.com");
MailAddress to = new MailAddress("to@mailserver.com");
MailMessage mm = new MailMessage(from, to);
mm.Subject = "Subject"
mm.Body = "Body";
SmtpClient client = new SmtpClient("proxy.mailserver.com", 8080);
client.Credentials = new System.Net.NetworkCredential("from@mailserver.com", "password");
client.Send(mm);
完全不需要将其合并到您的web.config中.
There is no need to incorporate it into your web.config at all