我正在使用以下代码,它似乎每次在 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);
}
}
但是在 Windows XP 上我得到:
No connection could be made because the target machine actively refuses it
我已经检查并完全禁用了 Windows 防火墙...