大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
一:问题在于???
创新互联建站坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都网站制作、成都做网站、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的王益网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!1:163邮箱,qq邮箱默认未开通第三方邮箱,需要自己去开通
2:开通之后会获得授权码,不可以使用原来的密码,密码改为授权码
二:解决方法
1:在qq邮箱的设置中找到如图,开启smpt服务
2:设置UseDefaultCredentials 为false ,创建,smtpClient.Credentials = new NetworkCredential(emailSetting.Username, Password(这里是授权码));
三:代码如下
public class EmailSettings
{
public string MailToAddress = "7126252@qq.com";
public string MailFromAddress = "9067447@qq.com";
public bool UseSsl = true;
public string Username = "9067447@qq.com";
public string Password = "zdyzwmlndsdsdsad"; //要使用qq的 或者163邮箱的授权码
public string ServerName = "smtp.qq.com";
public int ServerPort = 25;
public bool WriteAsFile = false; //这里要false
public string FileLocation = "";
}
public class EmailOrderProcess:IOrderProcess
{
private EmailSettings emailSetting;
public EmailOrderProcess(EmailSettings setting)
{
emailSetting = setting;
}
public void ProcessOrder(Cart cart,ShoppingDetials shoppingDetials)
{
using(var smtpClient=new SmtpClient())
{
smtpClient.EnableSsl = emailSetting.UseSsl;
smtpClient.Host = emailSetting.ServerName;//smtp.qq.com
smtpClient.Port = emailSetting.ServerPort;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new NetworkCredential(emailSetting.Username, emailSetting.Password);
if (emailSetting.WriteAsFile) { }
StringBuilder body = new StringBuilder().Append("A new order has been submitted");
var mailMessage = new MailMessage(emailSetting.MailFromAddress, emailSetting.MailToAddress, "A new order", body.ToString());
smtpClient.Send(mailMessage);
}
}
}