在asp.net MVC中使用localhost时,smtt不发送已发布的电子邮件

时间:2018-09-01 11:23:45

标签: c# asp.net asp.net-mvc smtp

我的代码是

WebMail.SmtpServer = "smtp.gmail.com";
            //gmail port to send emails  
            WebMail.SmtpPort = 25;
            WebMail.SmtpUseDefaultCredentials = false;
            //sending emails with secure protocol  
            WebMail.EnableSsl = true;
            //EmailId used to send emails from application  
            WebMail.UserName = "myemail";
            WebMail.Password = "mypassword";

            //Sender email address.  
            WebMail.From = "myemail";

            //obj.EMailBody = "Dear" + query.FirstName + "Your password is: " + query.Password;

            //obj.EmailSubject = "Password Recovery";
            //WebMail.Send(to: obj.ToEmail, subject: obj.EmailSubject, body: obj.EMailBody, cc: obj.EmailCC, bcc: obj.EmailBCC, isBodyHtml: true);
            findThatUser.EMailBody = "Dear " + findThatUser.firstName + " " + findThatUser.lastName +" "+ "Your Key to reset Password is " + key;
            findThatUser.EmailSubject = "Password Recovery";
            WebMail.Send(to: findThatUser.emailAddress, subject: findThatUser.EmailSubject, body: findThatUser.EMailBody, isBodyHtml: true);

在web.config中,我的设置是

<system.net>
<mailSettings>
  <smtp from="sugarlydate@gmail.com">
    <network host="smtp.gmail.com" port="25" userName="myemail" password="mypassword" enableSsl="true" />
  </smtp>
</mailSettings>

现在,当我尝试在localhost上发送电子邮件时,它可以正常工作,但是当我尝试在已发布的网站上发送时,它不起作用并且没有收到任何错误。我告诉你lesssecureapps已在Google设置中启用

0 个答案:

没有答案