1

i get some problem when i try to send email notif with smtp using Gmail host

This is my code

 DataTable dtEmail = objBLL.SubmitEmailPelaporan(userTest);

string content = dtEmail.Rows[0]["MsgDetail"].ToString();
string subject = dtEmail.Rows[0]["Subject"].ToString();


MailMessage mail = new MailMessage();
mail.IsBodyHtml = true;


mail.From = new MailAddress(emailSender);
mail.To.Add(new MailAddress(emailTo));

mail.Subject = subject;
mail.Body = content;


SmtpClient SmtpServer = new SmtpClient();
SmtpServer.Host = "smtp.gmail.com";
SmtpServer.Port = 587;
SmtpServer.UseDefaultCredentials = true;
SmtpServer.Credentials = new System.Net.NetworkCredential(emailSender, emailPassword);
//SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
SmtpServer.EnableSsl = true;



SmtpServer.Send(mail);

My Error is "Failure to sending email" Inner Exception "Unable to connect the remote server"

i already to searhing too in google with my proble but i got the same error, failure sending email...unable to connect the remote server.

Thx All for helping me

Luke
  • 22,826
  • 31
  • 110
  • 193
  • It's probably true, it can't connect to the server. Have you checked your credentials? – Luke Apr 21 '17 at 09:06
  • do you double check your NetworkCredentioal ? do you check that is not blocked by your firewall ? Do you have see all the other similar question for the same error ? – Aristos Apr 21 '17 at 09:17
  • and now the error is "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at" – Azhar Setiawan Apr 21 '17 at 09:20
  • yah i think the firs error is about my proxy connection – Azhar Setiawan Apr 21 '17 at 09:21
  • Possible duplicate of [Sending email in .NET through Gmail](http://stackoverflow.com/questions/32260/sending-email-in-net-through-gmail) – VDWWD Apr 21 '17 at 10:31

3 Answers3

0

This happens when you try login from different time zone or IP Address Computer. sign in to gmail once with your credentials. They will ask for the confirmation, confirm it and log out.

Hopes it help..!!!

farrukh aziz
  • 162
  • 1
  • 2
  • 9
0

Have you turned on less secure apps? check here

Also check antivirus mail policy

sda11
  • 61
  • 1
  • 6
0

For the error: "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at", you would have got an Email(Account of the 'emailSender' in the code) of subject: "Review blocked sign-in attempt".

Open that email and click on 'Secure Your Account' where in you will be directed to page where you can turn OFF"Disable access for less secure apps". Doing this should fix your issue.

Boney
  • 2,072
  • 3
  • 18
  • 23