This is my code and it is giving me an SMTP Exception. I tried to change my port to 25 but didn't work. Plus i am connected to the internet i can't figure out whats the problem
private void RecovaryEmail(string username)
{
ManagerUserAccount mgrUserAccount = new ManagerUserAccount();
UserAccount ua = mgrUserAccount.SearchUserAccount(username);
ManagerStaff mgrStaff = new ManagerStaff();
Staff s = mgrStaff.SearchStaff(ua.StaffID);
try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("restaurant.reservation.and.order.system@gmail.com");
mail.To.Add(s.Email);//members email
mail.Subject = "Password Recovary";
mail.Body = "Dear " + s.FirstName + " " + s.LastName + ",\nIn this email you have your account details.\n\nUsername: " + ua.Username + "\nPassword: " + ua.Password + "\nRecovery Question: " + ua.SecurityQuestion + "\nRecovery Answer: " + ua.SecurityAnswer + ".";
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("restaurant.reservation.and.order.system@gmail.com", "password");
SmtpServer.EnableSsl = true;
SmtpServer.Host = "smtp.gmail.com";
SmtpServer.Send(mail);
MessageBox.Show("Email has been sent to " + s.Email);
}
catch (SmtpException se)
{
MessageBox.Show("Please, connect to the internet to be able too send email.");//se.ToString());
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}