I am using smtp client to send email, but problem is that when i tried to send email form my local system email successfully sent but i deployed on server than email not sent. Here is my code
try
{
MailMessage mail = new MailMessage();
mail.To.Add(receiver);
mail.From = new MailAddress("lms.mannconsultant@gmail.com");
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = true;
if (attachment != null)
{
mail.Attachments.Add(attachment);
}
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Credentials = new System.Net.NetworkCredential("xxxxx@gmail.com", "xxxxxx");
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Port = 587;
smtp.Send(mail);
return true;
}
catch
{
return false;
}