I am currently developing an application in C# using WPF.
I need the program to be able to send an email to the users email account. The email needs to be sent through my own SMTP server which is using the free Google Apps version for email.
I have put the following code in order to send the message.
try
{
SmtpClient smtpClient = new SmtpClient();
smtpClient.Host = "smtp.gmail.com";
smtpClient.Port = 465;
smtpClient.Credentials = new NetworkCredential("myusername", "mypassword");
smtpClient.EnableSsl = true;
MailMessage message = new MailMessage();
message.To.Add(getEmail());
message.Subject = "Password Manager Sync Account Created";
message.From = new MailAddress("username@domain.com");
message.Body = "My Email message"
smtpClient.Send(message);
}
catch (Exception ex)
{
MessageBox.Show("Error Occurred" + ex.Message, "Email Failed", MessageBoxButton.OK, MessageBoxImage.Error);
However, when this code runs it instead just displays an error to say that the operation timed out.
What could be wrong with this?
I have a program that uses SMTP and it goes through port 587 on gmail. Try that.