我正在开发一个应用程序,用于将文件从我的硬盘驱动器和电子邮件附加到特定的电子邮件地址。当我使用我的个人互联网连接时,它正常工作。但是当我使用我的大学互联网连接时出现问题。它通过本地代理服务器连接。 这是我实现发送电子邮件的功能。如何在发送电子邮件时自动检测本地代理服务器。
public static void SendAttachedEmail()
{
try
{
MailMessage mail = new MailMessage();
SmtpClient client = new SmtpClient("smtp.gmail.com");
MailAddress fromAddress = new MailAddress("FromEmail@gmail.com");
MailAddress toAddress = new MailAddress("ToEmail@gmail.com");
mail.From = fromAddress;
mail.To.Add(toAddress);
mail.Subject = "Ledger Files";
mail.Body = "HP-PC";
Attachment file;
file = new Attachment(path + filename);
mail.Attachments.Add(file);
client.Port = 587;
NetworkCredential credentials = new NetworkCredential("FromEmail@gmail.com", "FromEmailPassword");
client.Credentials = credentials;
client.EnableSsl = true;
client.Send(mail);
Console.WriteLine("Sending Successful : " + filename);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
答案 0 :(得分:0)
您是否检查过您是否可以从大学实际访问SMTP服务器(您是否尝试登录您的gmail帐户/ hotmail帐户并实际发送内容作为附件?可能会被阻止。< / p>