打开包含附件的默认邮件管理器 (Windows)
本文关键字:管理器 Windows 默认 包含附 | 更新日期: 2023-09-27 18:30:31
>我需要通过默认邮件管理器打开一封带有附件的新电子邮件(没有SMTP代码)我使用:
System.Diagnostics.Process.Start(String.Format("mailto:{0}", txtEmail.Text))
也可以添加附件吗?
我可以试试这个
http://www.codeproject.com/Articles/17561/Programmatically-adding-attachments-to-emails-in-C
但我应该明白,Outlook 对客户端计算机的需求总是有Microsoft......
这
是不可能的?!
我提供了一个使用System.Net.Mail命名空间的详细方法;
private void button1_Click(object sender, EventArgs e)
{
SmtpClient smtpserver = new SmtpClient();
smtpserver.Credentials = new NetworkCredential("email@domain", "passphrase");
smtpserver.Port = 587;
smtpserver.Host = "smtp.live.com";
smtpserver.EnableSsl = true;
MailMessage mail = new MailMessage();
mail.From = new MailAddress("email@domain");
mail.To.Add("recipient@domian");
mail.Subject = "testing";
string pathTOAttachment;
string _Attachment = pathToAttachment;
Attachment oAttch = new Attachment(_Attachment);
mail.Attachments.Add(oAttch);
mail.Body = "message body";
ThreadPool.QueueUserWorkItem(delegate
{
try
{
smtpserver.Send(mail);
}
//you can get more specific in here
catch
{
MessageBox.Show("failure sending message");
}
});
}
值得注意(在此代码示例中未考虑):
- 有些
- ISP可能会对附件施加大小限制,有些则确保在尝试发送电子邮件之前对其进行检查。
- SMTP 主机/端口可能会有所不同,最有效的方法是检查定期更新的数据库,或者让用户自己设置它们。
- 线程部分完全与 UI 响应能力有关,但是,如果用户关闭主应用窗口而邮件仍在发送,它将被抢占。