我正在尝试使用Visual Studio C#和SMTP从我的桌面应用程序发送自动电子邮件。它直接连接到Wi-Fi时有效,但是当我连接到我们设置的VLAN时,SmtpClient.Send()
超时。
public static void SendEmail(string toAddress, string subject, string body)
{
string senderID = "email";
const string senderPassword = "password";
try
{
SmtpClient smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
Credentials = new System.Net.NetworkCredential(senderID, senderPassword),
Timeout = 30000,
};
if (IsValidEmail(toAddress))
{
MailMessage message = new MailMessage(senderID, toAddress, subject, body);
smtp.Send(message);
}
else throw new Exception();
}
catch (Exception)
{
throw;
}
}
我们正在使用静态IP,所以我想也许它与DNS有关,因为SMTP主机不是特定的IP。