Error with Sending Mail via website

Donald Symmons 2,856 Reputation points
2022-05-19T23:42:24.537+00:00

Hello Forum,
I need your help in resolving an issue I am currently facing. I cannot send mail from my website
to another email address. Before hosting my site, I tested it and it worked but ever since I hosted
my website it has not been working. I really do not know what could cause the error. All the login
credentials are correct but I keep getting the error. Please I really need help and direction to resolve this.
I am using office365 as my mail
Here is my code behind:

 using (MailMessage mm = new MailMessage("help@josmade.com", mailtxtbx.Text))
        {
            mm.Subject = "Account Activation";
            string body = "Hello " + txtname.Text.Trim() + ",";
            body += "<br /><br />Your Registration was successful.";
            body += "<br /><br />Please click the Button below to activate your account";
            body += "<br /><br /><a style='display: block; width: 130px; height: 15px; background: #355171;padding: 10px;font-family: Nunito; text-align:center; border-radius: 5px;color: white;font-weight: bold;text-decoration: none;' href = '"
            + Request.Url.AbsoluteUri.Replace("signup", "AccountActivation.aspx?ActivationCode="
            + activationCode) + "'>Click here to activate your account.</a>";
            body += "<br /><br />Thanks";
            mm.Body = body;
            mm.IsBodyHtml = true;

            SmtpClient SMTP = new SmtpClient("smtp.office365.com", 587);
            SMTP.UseDefaultCredentials = false;
            SMTP.Credentials = new NetworkCredential()
            {
                UserName = "help@josmade.com",
                Password = "xxxxxxxxxxxxx"
            };
            SMTP.EnableSsl = true;
            SMTP.Send(mm);
        }
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,254 questions
{count} votes

Accepted answer
  1. Lan Huang-MSFT 25,551 Reputation points Microsoft Vendor
    2022-05-20T03:25:45.447+00:00

    Hi @Donald Symmons ,
    You can try the following methods:

    • Check if the server OS hosting your website has a firewall rule to deny it.
    • You can check if something else is using the port with netstat:
      netstat -ano | findstr <your port number>
    • If nothing is already using it, the port might be excluded, try this command to see if the range is blocked by something else:
      netsh interface ipv4 show excludedportrange protocol=tcp
    • Try to restart the Host Network Service on windows service program.
      net stop hns
      net start hns
    • Restarting the Internet Information Services (IIS):
      iisreset

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful