question

Donald-0878 avatar image
0 Votes"
Donald-0878 asked Bruce-SqlWork commented

Error with Sending Mail via website

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);
         }

dotnet-aspnet-generaldotnet-aspnet-webformsdotnet-aspnet-webpages
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

This is error I got on my broswer
203799-mail-error.png


0 Votes 0 ·
mail-error.png (78.9 KiB)

Please investigate the difference in access right of the worker processes between the development environment and IIS environment.

0 Votes 0 ·

1 Answer

LanHuang-MSFT avatar image
0 Votes"
LanHuang-MSFT answered Bruce-SqlWork commented

Hi @Donald-0878,
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.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

All of the you mentioned, do I contact my host provider or do I effect myself?

0 Votes 0 ·

you contact your host provider to allow access to the port by your application.





0 Votes 0 ·