Search code examples
c#asp.netsmtpgmailsystem.net.mail

ASP.NET - Error sending email Messages


I checked other questions, and i was able to resolve some errors in my code, but smtp.Credentials = nc; , where nc is my Network credentials, is throwing an exception, Request action aborted on MFE proxy, SMTP server is not available.

Please, any help would be appreciated. Below, is my code :

           MailMessage msg = new MailMessage();
            msg.From = new MailAddress("fromemail");
            msg.To.Add("toemail");
            msg.Subject = "Contact Us";
            msg.Body = cname.Text + "sent me this message" + cmessage.Text + "with this email, " + email.Text;
            msg.IsBodyHtml = true;

            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.gmail.com";
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
            smtp.EnableSsl = false;
            smtp.UseDefaultCredentials = false;
            smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
            NetworkCredential nc = new NetworkCredential();
            nc.UserName = "fromemail";
            nc.Password = "fromemailpwd";
            smtp.Credentials = nc;
            smtp.Port = 587;
            smtp.Send(msg);
            sPanel.Visible = true;
            lblSuccess.Text = "Success! Thanks for contacting us, we will get back to you soon.";

I changed the smtp.Credentials = nc to smtp.Credentials = new NetworkCredentials("fromemail", "fromemailpwd"); Now, it is this line, smtp.Send(msg), that is throwing the exception.


Solution

  • I wasn't able to get the same error message that you saw, but check out this answer : Request action aborted on MFE proxy, SMTP server is not available

    However, I do know that Gmail requires EnableSSL = True