我想在客户验证commande之后向admin发送邮件,但是当点击按钮valider时我收到此错误: 邮箱不可用的信件。服务器响应为:5.7.3请求的操作中止;用户未经过身份验证。 我没有在互联网上找到任何解决方案。
[HttpPost]
public async Task<ActionResult> Index2(LigneCommandeT LigneCommandeT , string submit)
{
switch (submit)
{
case "Ajouter" :
context.LigneCde.Add(LigneCommandeT);
context.SaveChanges();
return RedirectToAction("Index2");
break;
case "Valider" :
// var message = EMailTemplate("Welcome");
await MessageServices.SendEmailAsync("Namegmail.com", "Welcome!", "message");
return RedirectToAction("Index3");
break;
default :
return RedirectToAction("Index2");
break;
}
}
这是SendMail方法:
public async static Task SendEmailAsync(string email , string subject ,string message)
{
try
{
var _email="Name@gmail.com"; // sender's email
var _epass = ConfigurationManager.AppSettings["EmailPassword"]; // get our password from web.config
var _dispName = "Sabrine";
MailMessage MyMessage = new MailMessage();
MyMessage.To.Add(email);
MyMessage.From = new MailAddress(_email,_dispName);
MyMessage.Subject = subject ;
MyMessage.Body = message ;
MyMessage.IsBodyHtml = true;
using(SmtpClient smtp = new SmtpClient())
{
smtp.EnableSsl =true ;
smtp.Host = "smtp.live.com";
smtp.Port = 587 ;
smtp.UseDefaultCredentials = false ;
smtp.Credentials = new NetworkCredential(_email,_epass);
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.SendCompleted += (s,e) => {smtp.Dispose();} ;
await smtp.SendMailAsync(MyMessage);
}
}
catch(Exception ex)
{
throw ex ;
}
这是Web.config的一部分:
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="EmailPassword" value="" />
</appSettings>
<system.net>
<mailSettings>
<smtp deliveryMethod="Network">
<network enableSsl="true" host="smtp.live.com" port="587" defaultCredentials="false" userName="Name@gmail.com" password=""/>
</smtp>
</mailSettings>
谢谢,
答案 0 :(得分:0)
请按如下方式编辑您的代码;
enum c_color{BLACK=30,RED=31,GREEN=32,YELLOW=33,BLUE=34,MAGENTA=35,CYAN=36,WHITE=37};
enum c_decoration{NORMAL=0,BOLD=1,FAINT=2,ITALIC=3,UNDERLINE=4,RIVERCED=26,FRAMED=51};
void pr(const string str,c_color color,c_decoration decoration=c_decoration::NORMAL){
cout<<"\033["<<decoration<<";"<<color<<"m"<<str<<"\033[0m";
}
void prl(const string str,c_color color,c_decoration decoration=c_decoration::NORMAL){
cout<<"\033["<<decoration<<";"<<color<<"m"<<str<<"\033[0m"<<endl;
}
答案 1 :(得分:0)
代码中的以下行未获得任何password
或更确切地说password
为空string
:
var _epass = ConfigurationManager.AppSettings["EmailPassword"];
由于此设置了config
:
<add key="EmailPassword" value="" />
如果你看清楚value
是空的string
。您必须将其替换为所需的Password
,如下例所示:
<add key="EmailPassword" value="YourPassword" />