在我的程序的一部分中,应用程序应该搜索安装目录中的某些文件,如果找到,应该通过电子邮件发送这些文件。到目前为止,我有:
try
{
MailMessage mail = new MailMessage();
string[] file1 = Directory.GetFiles("some directories", "some files");
string[] file2 = Directory.GetFiles("some directories", "some files");
string[] file3 = Directory.GetFiles("some directories", "some files");
foreach (var file in file1)
{
Attachment someFiles = new Attachment(file);
mail.Attachments.Add(someFiles);
}
foreach (var file in file2)
{
Attachment someFiles1 = new Attachment(file);
mail.Attachments.Add(someFiles1);
}
foreach (var file in file3)
{
Attachment someFiles2 = new Attachment(file);
mail.Attachments.Add(someFiles2);
}
SmtpClient server = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("someone@gmail.com");
mail.To.Add("someone@gmail.com");
mail.Subject = "subject";
server.Port = 587;
server.Credentials = new System.Net.NetworkCredential("someone@gmail.com", "password");
server.EnableSsl = true;
server.Send(mail);
}
catch (Exception ex)
{
string stat = ex.ToString();
MessageBox. Show(stat);
}
没有例外,但没有发送电子邮件。问题在哪里?