Aniruddha Acharya

Aniruddha Acharya

  • NA
  • 304
  • 20.2k

message sending on email id by website

Nov 27 2019 5:49 AM
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();
}
}
 
 
 
 

Answers (6)