摘要:一:问题在于??? 1:163邮箱,qq邮箱默认未开通第三方邮箱,需要自己去开通 2:开通之后会获得授权码,不可以使用原来的密码,密码改为授权码 二:解决方法 1:在qq邮箱的设置中找到如图,开启smpt服务 2:设置UseDefaultCredentials 为false ,创建,smtpClient.Credentials = new Network
一:问题在于???
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);
}
}
}
相关文章推荐
已有家长中招!“录取通知书”邮件暗藏骗局2022-09-06
连接企微和钉钉,新网全球邮助力企业协同办公2022-09-27
快速申请搭建免费企业邮箱的教程2022-09-16
如何避免你的外贸开发信被当成垃圾邮件?2022-09-14
2021年,全国企业邮箱用户共收发邮件约7637.7亿封2022-09-13