C# 打开包含附加文件的默认邮件管理器(Windows)

C# 打开包含附加文件的默认邮件管理器(Windows),c#,.net,vb.net,email,C#,.net,Vb.net,Email,我需要通过默认邮件管理器(无SMTP代码)打开带有附件的新电子邮件 我使用: 是否也可以添加附件 我可以试试这个 但我应该明白,客户端计算机始终需要Microsoft Outlook…这是不可能的 我提供了一个使用System.Net.Mail名称空间的详细方法 private void button1_Click(object sender, EventArgs e) { SmtpClient smtpserver = new SmtpClient(); smtpserve

我需要通过默认邮件管理器(无SMTP代码)打开带有附件的新电子邮件 我使用:

是否也可以添加附件


我可以试试这个

但我应该明白,客户端计算机始终需要Microsoft Outlook…

这是不可能的
我提供了一个使用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可能会对附件施加大小限制,有些isp会确保您在尝试发送电子邮件之前检查附件
  • smtp主机/端口可能会有所不同,最有效的方法是对照定期更新的数据库进行检查,或者让用户自己设置
  • 线程部分是关于UI响应的,但是,如果用户在邮件仍在发送的情况下关闭主应用程序窗口,它将被抢占
  • 这是不可能的
    我提供了一个使用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可能会对附件施加大小限制,有些isp会确保您在尝试发送电子邮件之前检查附件
  • smtp主机/端口可能会有所不同,最有效的方法是对照定期更新的数据库进行检查,或者让用户自己设置
  • 线程部分是关于UI响应的,但是,如果用户在邮件仍在发送的情况下关闭主应用程序窗口,它将被抢占

  • 可能的副本实际上不发送电子邮件,它会启动计算机的默认电子邮件客户端,并带有预填充的字段。@失望先生:好的,如果您愿意,我想打开默认电子邮件客户端,并在磁盘上生成一个图像作为附件…可能的副本实际上不发送电子邮件,它启动机器的默认电子邮件客户端,并带有预先填充的字段。@失望先生:好的,如果你愿意,我想打开默认电子邮件客户端,并在磁盘上生成一个图像作为附件…我说过它不可能:-),我的无知,试试这个:我说过它不可能:-),我的无知,试试这个: