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);
}
}
}
西部数码是专业企业邮箱的官方正规提供商,21年行业经验,提供安全稳定,简单易用,高性价比的企业邮箱,按需自由定制,不限空间,极速收发,能够满足用户对企业邮箱的不同需求。可以通过以下几种方式注册、申请、购买、试用、开通企业邮箱:
1、登录https://www.west.cn/services/mail/在线咨询申请试用或购买;
2、直接致电028-62778877申请试用或正式购买开通;