我想发送电子邮件中的附件,因此我想先将附件文件保存在文件夹中。如何在Windows应用程序中的文件夹中保存文件
那么我现在的代码发生了什么事情,邮件正在附件中,但我的文件没有保存到
ATTACHMENT
文件夹中。
这里是我试图
for (int i = 0; i < table.Rows.Count; i++)
{
if (1 == 1)
{
string StrPriBody = "This is a test mail for checking notification.";
MailMessage mail = new MailMessage();
mail.Subject = "Daily Holding followup scheduler";
mail.From = new System.Net.Mail.MailAddress("[email protected]");
SmtpClient smtp = new SmtpClient();
smtp.Timeout = 1000000;
smtp.Port = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["Port"]);
smtp.UseDefaultCredentials = true;
smtp.Host = System.Configuration.ConfigurationManager.AppSettings["MailHost"];
smtp.Credentials = new NetworkCredential(mail.From.ToString(), "PS123456");
smtp.EnableSsl = true;
mail.To.Add(new MailAddress("[email protected]"));
mail.IsBodyHtml = true;
mail.Body = StrPriBody;
DataSet ds = new DataSet();
ds.Tables.Add(table);
ds.Tables[0].TableName = "Post sale follow up entries auto mailer";
SaveFileDialog save = new SaveFileDialog();
save.InitialDirectory = "\\Attachment";
save.RestoreDirectory = true;
ExcelLibrary.DataSetHelper.CreateWorkbook("Employee_Details.xls", ds);
mail.Attachments.Add(new Attachment("Employee_Details.xls"));
smtp.Send(mail);
foreach (Attachment attachments in mail.Attachments)
{
attachments.Dispose();
}
为什么你的文件应该保存在附件文件夹中?你如何告诉你的ExcelLibrary在该文件夹中创建文件? – Steve
@Steve:我不知道如何在文件夹中创建该文件?任何帮助 – learner
你不需要SaveFile对话框来做到这一点(并在你的代码中定义它,但你没有使用它)。只需使用[File.Copy](https://msdn.microsoft.com/en-us/library/system.io.file.copy(v = vs.110).aspx) – Pikoh