Hi,
I am using this code for send mail message from my website: This Code is running on local host, but when i updated on server then not working.
protected void buttonSend_Click(object sender, EventArgs e)
{
try
{
SmtpClient client = new SmtpClient("smtp.gmail.com",587);
client.EnableSsl = true;
client.Timeout = 10000;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("EmailID", "Password");
MailMessage msg = new MailMessage();
msg.To.Add("EmailID");
msg.From = new MailAddress( textBoxTo.Text);
msg.Subject = textBoxSubject.Text;
msg.Body = " Name = " + textBoxName.Text + "" + "\n" + " Mobile Number: " + textBoxMobile.Text + "" + "\n" + " This Mail is from = " + textBoxTo.Text + " " + "\n" + " Subject = " + textBoxSubject.Text + " " + "\n" + " Message = " + textBoxMsg.Text + " ";
client.Send(msg);
lblMessageBox.Text = ("Mail Sent successfully!!!");
}
catch (Exception ex)
{
lblMessageBox.Text = ex.ToString();
}
}

Guest UserRank #816 · 2.8K reputationPosted Nov 27, 2019, 1:02 AM EST
Aniruddha AcharyaRank #8,429 · 222 reputationPosted Nov 27, 2019, 6:00 PM EST
Jaimin ShethiyaRank #177 · 13.7K reputationPosted Nov 27, 2019, 8:55 PM EST
can you please once change the smtp port 587 to 25 when you have upload your code in server and after test it's working or not.
And also share the exception so will investigate for better helping for you.
Thanks
Aniruddha AcharyaRank #8,429 · 222 reputationPosted Nov 27, 2019, 11:42 PM EST
Less secure app access : On
Jaimin ShethiyaRank #177 · 13.7K reputationPosted Nov 27, 2019, 11:45 PM EST
Sam187 reputationPosted Nov 28, 2019, 12:27 AM EST