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)
    //create the mail message
    MailMessage mail = new MailMessage();
    //set the addresses
    mail.From = new MailAddress("");
    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("");

    NetworkCredential Credentials = new NetworkCredential("", "MyPassword");
    smtp.Credentials = Credentials;
    writeToLog("Email Sent !", 2);
    catch (Exception e)
    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