0

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.

theB
  • 6,450
  • 1
  • 28
  • 38
Jouwana
  • 1
  • 3

4 Answers4

0

add authenticated NetworkCredential

System.Net.NetworkCredential smtpUser = new System.Net.NetworkCredential("admin@hotmail.com", "password");
smtpClient.Credentials = smtpUser;
Genish Parvadia
  • 1,437
  • 3
  • 17
  • 30
0

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

Community
  • 1
  • 1
Damith
  • 62,401
  • 13
  • 102
  • 153
  • I had set it up before and it didnt work cause of hotmail blocking it the mail, i tried to enable it to work but couldnt, so i used gmail and enabled less than secure apps and it now works – Jouwana Oct 18 '15 at 06:27
0

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)
            {

            }

        }
-1

From your sender account, view the email inbox and say it is you to allow the third party to send emails.

Salma Tofaily
  • 113
  • 1
  • 5