I’m using the following code which appears to work perfectly every time on Vista/Win7.
private void SendEmail(string subject, string body, string attach)
{
using (MailMessage message = new MailMessage("username@gmail.com", "username@gmail.com", subject, body))
{
message.IsBodyHtml = true;
if (!string.IsNullOrEmpty(attach))
{
Attachment attached = new Attachment(attach);
message.Attachments.Add(attached);
}
SmtpClient client = new SmtpClient("smtp.gmail.com", 587)
{
Credentials = new NetworkCredential("username@gmail.com", "password"),
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network
};
client.Send(message);
}
}
However on Windows XP I’m getting:
No connection could be made because the target machine actively refuses it
I’ve checked and Windows firewall is completely disabled…
Try from the Windows machine the following:
cmdtelnet smtp.gmail.com 587If it says connection refused or similar then it’s a firewall or network problem, unrelated with the code.