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();
}
}
6 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
SamPosted Nov 28, 2019, 5:27 AM
Jaimin ShethiyaPosted Nov 28, 2019, 4:45 AM
Aniruddha AcharyaPosted Nov 28, 2019, 4:42 AM
Less secure app access : On
Jaimin ShethiyaPosted Nov 28, 2019, 1:55 AM
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 AcharyaPosted Nov 27, 2019, 11:00 PM
Guest UserPosted Nov 27, 2019, 6:02 AM