Reputation: 25
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
Upvotes: 1
Views: 490
Reputation: 2202
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.
Upvotes: 0
Reputation: 33
Have you turned on less secure apps? check here
Also check antivirus mail policy
Upvotes: 0
Reputation: 172
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..!!!
Upvotes: 0