btnsnd_click
string usertype = string.Empty; DataTable dt = new DataTable(); try { for (int i = 0; i < grEmp.Rows.Count;i++ ) { CheckBox cb = (CheckBox)grEmp.Rows[i].FindControl("chkSelect"); if (cb.Checked == true) { if (cb != null && cb.Checked) { string emailid = grEmp.Rows[i].Cells[1].Text; SendEmailUsingGmail(emailid); dt.Clear(); dt.Dispose(); } ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), Guid.NewGuid().ToString(), "alert('Emails sent successfully');", true); } } ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), Guid.NewGuid().ToString(), "alert('Please check CheckBox');", true); } catch (Exception ex) { Response.Write("Error occured: " + ex.Message.ToString()); } finally { usertype = string.Empty; } } private void SendEmailUsingGmail(string toEmailAddress) { try { SmtpClient smtp = new SmtpClient(); smtp.Credentials = new NetworkCredential("anilkumar.hrs@gmail.com", "anil"); smtp.Port = 587; smtp.Host = "smtp.gmail.com"; smtp.EnableSsl = true; MailMessage message = new MailMessage(); message.From = new MailAddress("anilkumar.hrs@gmail.com"); message.To.Add(toEmailAddress); message.Subject = TxtSubject.Text; message.Body = TxtMessage.Text; smtp.Send(message); } catch (Exception ex) { Response.Write("Error occured: " + ex.Message.ToString()); } }
Error occured: 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
Quote:This generally happens when you try login from different time zone/IP/Computer. You production server and the mail id you have used both are in different time zone. Choose any of the one solution: 1) Log in to production server via remote access, and sing in to gmail once with your credentials. They will ask for the confirmation, confirm it and log out. Or 2) log in gmail to your local computer, Follow this Link and choose review this activity and take proper actions.
This generally happens when you try login from different time zone/IP/Computer. You production server and the mail id you have used both are in different time zone. Choose any of the one solution:
1) Log in to production server via remote access, and sing in to gmail once with your credentials. They will ask for the confirmation, confirm it and log out.
Or 2) log in gmail to your local computer, Follow this Link and choose review this activity and take proper actions.
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)