Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send mail works locally but not on server?

This code works locally, but when I upload it to my server on Godaddy, it does not send the e-mail. Any idea why it doesn't work on their server? What do I need to change?

try {
    MailMessage mail = new MailMessage();
    SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

    mail.From = new MailAddress("[email protected]");
    mail.To.Add("[email protected]");
    mail.Subject = "New sign up";
    mail.Body = "New member";

    SmtpServer.Port = 587;
    SmtpServer.Credentials = new System.Net.NetworkCredential("[email protected]", "**Mypass**");
    SmtpServer.EnableSsl = true;

    SmtpServer.Send(mail);
} catch(Exception ex) {
    throw ex;
}
like image 822
CsharpBeginner Avatar asked Oct 17 '25 03:10

CsharpBeginner


1 Answers

They may be blocking outgoing SMTP connections in order to prevent spammers from using their service to send spam. You should check what error messages you're getting and check your server host's policy.

like image 162
Keith Irwin Avatar answered Oct 18 '25 19:10

Keith Irwin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!