Sending email

Discussion in 'Site Programming, Development and Design' started by maric01, May 31, 2016.

  1. Hi,

    I'm trying to make a function work.

    I made a web application that will send email to user. User email could be hotmail, gmail or any other email. When sending email to myself (winhost hosted account) it's working but when trying to send to other email, I get this MailBox unavailable error : "Mailbox unavailable. The server response was: Authentication is required for relay"

    This is my function :

    private void SendMail(string from, string to)
    {
    try
    {
    //create the mail message
    MailMessage mail = new MailMessage();
    //set the addresses
    mail.From = new MailAddress("[email protected]");
    mail.To.Add(to); // can be gmail, hotmail or any other email

    //set the content
    mail.BodyEncoding = Encoding.UTF8;
    mail.Subject = "Bla bla bla";
    mail.Body = "Bla Bla Bla";

    //send the message
    SmtpClient smtp = new SmtpClient("mail.MyWinHostDomaine.com");

    NetworkCredential Credentials = new NetworkCredential("[email protected]", "MyPassword");
    smtp.Credentials = Credentials;
    smtp.Send(mail);
    writeToLog("Email Sent !", 2);
    }
    catch (Exception e)
    {
    Console.WriteLine(e.Message);
    writeToLog("Email error" + e.Message, 1);
    }
    }

    Thanks for the help
     
  2. Elshadriel

    Elshadriel Winhost Staff

    Means you are supplying either the wrong username or password when trying to send the email.
     
    Michael likes this.

Share This Page