sending mail successfully in localhost but don't when publish on server

Ahmed H. Yassin 1 Reputation point
2021-11-14T15:49:11.73+00:00

If it is working on local and now on server, then there may not be code issue, you need to check other things like firewall settings.
What error you got exactly ?
I use all ports number 587 /25/465, see below snippet
C#
Copy Code
MailMessage mail = new MailMessage();
mail.Subject = "Your Subject";
mail.From = new MailAddress("senderMailAddress");
mail.To.Add("ReceiverMailAddress");
mail.Body = "Hello! your mail content goes here...";
mail.IsBodyHtml = true;

SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.EnableSsl = true;
NetworkCredential netCre = new NetworkCredential("SenderMailAddress","SenderPassword" );
smtp.Credentials = netCre;

try
{
smtp.Send(mail);
}
catch (Exception ex)
{
}

Community Center Not monitored
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.