简体   繁体   中英

smtp.live Could not send the e-mail - error: Mailbox unavailable. The server response was: 5.7.3 Requested action aborted; user not authenticated

I saw all the other pages on stackoverflow that were about this problem and tried them but none of them worked.

im doing a website as a project for school, and I want the users to send an e-mail for them to report problems in, but it always gives me that error.

this is my code:

    protected void Sendbtn_Click(object sender, EventArgs e)
    {
    try
      {

        MailMessage mailMessage = new MailMessage();
        mailMessage = new     MailMessage("user@hotmail.com","my@hotmail.com");           
        mailMessage.Subject = "Problem from Gamer's Utopia";
        mailMessage.Body = this.msgtxt.Text;
        SmtpClient smtpClient = new SmtpClient(" smtp.live.com");

        smtpClient.EnableSsl = true;
        smtpClient.Send(mailMessage);
        Response.Write("E-mail sent!");
      }
    catch (Exception ex)
      {
        Response.Write("Could not send the e-mail - error: " + ex.Message);
      }
    }

I tried using authentication with username and password but it didnt work - unless I did it incorrectly.

add authenticated NetworkCredential

System.Net.NetworkCredential smtpUser = new System.Net.NetworkCredential("admin@hotmail.com", "password");
smtpClient.Credentials = smtpUser;

You need to set SmtpClient Credentials, for example

smtpClient.Credentials = new System.Net.NetworkCredential("youremail@hotmail.com", "password"); 

check below answer for sample code:

https://stackoverflow.com/a/9851590/2558060

Change your code according to this!!! It will perfectly work!!!

using (MailMessage mail = new MailMessage()) {

            SmtpClient client = new SmtpClient("smtp.live.com");
            mail.From = new MailAddress("from address");


            mail.Subject = "";

string message = "";

            mail.Body = message;
            try
            {
                mail.To.Add(new MailAddress("To Address"));

            }
            catch
            {

            }

            client.Credentials = new System.Net.NetworkCredential("smtp.live.com", "password");
            client.EnableSsl = true;


            try
            {
                System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
                client.Send(mail);
                mail.To.Clear();

            }
            catch (Exception ex)
            {

            }

        }

在您的发件人帐户中,查看电子邮件收件箱,并说您允许第三方发送电子邮件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM