代码之家  ›  专栏  ›  技术社区  ›  P a u l

是否从WinForms应用发送带有附件的电子邮件?

  •  3
  • P a u l  · 技术社区  · 15 年前

    我当前正在使用进程。开始从我的WinForms应用程序发送简单电子邮件。你能想出任何方法在电子邮件中添加文件附件吗(编辑:使用Process.Start?)

    我现在用的是:

    Process.Start("mailto:test@test.invalid?subject=" + HttpUtility.HtmlAttributeEncode("Application error report") + "&body=" + body);
    
    1 回复  |  直到 15 年前
        1
  •  7
  •   Community CDub    8 年前

    尝试这样的方法-->

    MailMessage theMailMessage = new MailMessage("from@email.com", "to@email.com");
    theMailMessage.Body = "body email message here";
    theMailMessage.Attachments.Add(new Attachment("pathToEmailAttachment"));
    theMailMessage.Subject = "Subject here";
    
    SmtpClient theClient = new SmtpClient("IP.Address.Of.Smtp");
    theClient.UseDefaultCredentials = false;
    System.Net.NetworkCredential theCredential = new System.Net.NetworkCredential("user@name.com", "password");
    theClient.Credentials = theCredential;
    theClient.Send(theMailMessage);
    

    好的,根据你的编辑和其他信息,我在 Jon Galloway , "Sending files via the default e-mail client" .