【问题标题】:send email containing password when user account is created创建用户帐户时发送包含密码的电子邮件
【发布时间】:2013-10-29 20:09:57
【问题描述】:

在创建用户帐户时尝试发送包含密码的电子邮件。 (在帮助下)How to send email from Asp.net Mvc-3?

public void SendEmail(string address, string subject, string message, string password)
    {
        string email = "emailAddress";
        //string password = "put-your-GMAIL-password-here";

        var loginInfo = new NetworkCredential(email, password);
        var msg = new MailMessage();
        var smtpClient = new SmtpClient("smtp.gmail.com", 587);

        msg.From = new MailAddress(email);
        msg.To.Add(new MailAddress(address));
        msg.Subject = subject;
        msg.Body = message;
        msg.IsBodyHtml = true;

        smtpClient.EnableSsl = true;
        smtpClient.UseDefaultCredentials = false;
        smtpClient.Credentials = loginInfo;
        smtpClient.Send(msg);
    }

但是 smtpClient.Send(msg);返回以下错误:

{System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
   at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response)
   at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, MailAddress from, Boolean allowUnicode)
   at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, Boolean allowUnicode, SmtpFailedRecipientException& exception)
   at System.Net.Mail.SmtpClient.Send(MailMessage message)
   at ACCS.StockControl.Controllers.UserLoginRecordController.SendEmail(String address, String subject, String message, String password)
   at ACCS.StockControl.Controllers.UserLoginRecordController.EditModalPOST(UserLoginRecordEditModalVM model)}

有什么想法吗?

【问题讨论】:

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


【解决方案1】:

试一试

 smtpClient.EnableSsl = false;

【讨论】:

    【解决方案2】:
     MailMessage loginInfo = new MailMessage();
     loginInfo.To.Add("Emailaddress");
     loginInfo.From = new MailAddress("FromEmailaddress");
     loginInfo.Subject = "Subject";
     loginInfo.Body = "Body of the mail";
     loginInfo.IsBodyHtml = true;
    
     SmtpClient smtp = new SmtpClient();
     smtp.Host = hostname;
     smtp.Port = 25; //in my case i am using 25
     smtp.EnableSsl = false; //enable ssl is set to false
     smtp.Credentials = new System.Net.NetworkCredential(sEmailId, sPassword);
     smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
     smtp.Send(loginInfo);
     {
       Label.Visible = true;
       Label.Text = "A mail has been sent to you with the your username. Please check your inbox.";
     }
    

    【讨论】:

      【解决方案3】:

      可能只是密码和用户名错误。

      请尝试另一个假密码,(例如“thisPasswordIsSurelyDontWork”)。 如果您的例外情况相同,那么您必须检查您的信用证、用户名、密码

      //或尝试

       smtpClient.UseDefaultCredentials = true;
      

      【讨论】:

        猜你喜欢
        • 2019-06-18
        • 2019-07-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-07-10
        • 1970-01-01
        • 2022-11-07
        • 1970-01-01
        相关资源
        最近更新 更多