-1

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;
        }

1 Answers1

0

There can be many reasons for that.By looking at your code i suggest first you verify weather any exception is generated when this code executes in server(log exception).This will help to investigate further.Also check port(587) you are using in code is not blocked by server firewall(if enabled in server.)

ctor
  • 198
  • 2
  • 12