I'm trying to send a simple test email to check how the mail class works in C#, but when trying to call smtp.send(message);
I get the following error:
SocketException: No connection could be made because the target machine actively refused it 173.194.207.109:587
I have looked around at the packets in wireshark (although admittedly I don't have the knowledge to make sense of them) and it seems like Google is sending back a [RST, ACK] packet every time I try to send the email. Is there a way to further diagnose this?
var fromAddress = new MailAddress("FROM@gmail.com", "FROM NAME");
var toAddress = new MailAddress("TO@gmail.com", "TO NAME");
const string fromPassword = "password";
const string subject = "Subject";
const string body = "Body";
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
}