如何在C#中通过代理服务器发送电子邮件 [英] How can I send email through proxy server in C#

查看:593
本文介绍了如何在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


这篇关于如何在C#中通过代理服务器发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆