Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在c#中向mailto添加附件?_C#_Unity3d - Fatal编程技术网

如何在c#中向mailto添加附件?

如何在c#中向mailto添加附件?,c#,unity3d,C#,Unity3d,在上述代码中,附件不起作用。是否有其他方法可以使用C#中的mailto:link添加附件?您可以使用具有该属性的。比如: string email ="sample@gmail.com"; attachment = path + "/" + filename; Application.OpenURL ("mailto:" + email+" ?subject=EmailSubject&body=Em

在上述代码中,
附件
不起作用。是否有其他方法可以使用C#中的mailto:link添加附件?

您可以使用具有该属性的。比如:

string email ="sample@gmail.com";
attachment = path + "/" + filename;
Application.OpenURL ("mailto:" + 
                      email+"
                      ?subject=EmailSubject&body=EmailBody"+"&attachment="+attachment);

您可以这样尝试:

message.Attachments.Add(new Attachment(yourAttachmentPath));
以上代码使用MAPI32.dll

它可能不会附加文档,因为您可以自由访问 用于实现mailto协议的电子邮件客户端的 分析附件子句。您可能不知道什么是邮件客户端 安装在PC上,因此它可能不总是工作-Outlook当然可以 不支持使用mailto的附件


mailto:不正式支持附件。我听说Outlook 2003将使用以下语法:

using SendFileTo;

namespace TestSendTo
{
    public partial class Form1 : Form
    {
        private void btnSend_Click(object sender, EventArgs e)
        {
            MAPI mapi = new MAPI();

            mapi.AddAttachment("c:\\temp\\file1.txt");
            mapi.AddAttachment("c:\\temp\\file2.txt");
            mapi.AddRecipientTo("person1@somewhere.com");
            mapi.AddRecipientTo("person2@somewhere.com");
            mapi.SendMailPopup("testing", "body text");

            // Or if you want try and do a direct send without displaying the 
            // mail dialog mapi.SendMailDirect("testing", "body text");
        }
    }
}

更好的处理方法是使用System.Net.mail.Attachment在服务器上发送邮件

<a href='mailto:name@domain.com?Subject=SubjTxt&Body=Bod_Txt&Attachment=""C:\file.txt"" '>

你为什么不看看System.net.mail呢,你可以用一种更简单的方式来实现,它实现了所有必需的类,比如mailaddress,以及用于附件目的的附件类。可能会重复:“Outlook当然不支持使用mailto的附件。”它适用于某些版本,但你的权利,你不知道安装了什么邮件客户端,所以我建议使用C#System.Net.mail.Attachment。@MaxSassen:-这就是为什么在发布答案后,我添加了使用
System.Net.mail
的选项。你刚刚复制了帖子:只需链接到它
public static void CreateMessageWithAttachment(string server)
{
    // Specify the file to be attached and sent.
    // This example assumes that a file named Data.xls exists in the
    // current working directory.
    string file = "data.xls";
    // Create a message and set up the recipients.
    MailMessage message = new MailMessage(
       "jane@contoso.com",
       "ben@contoso.com",
       "Quarterly data report.",
       "See the attached spreadsheet.");

    // Create  the file attachment for this e-mail message.
    Attachment data = new Attachment(file, MediaTypeNames.Application.Octet);
    // Add time stamp information for the file.
    ContentDisposition disposition = data.ContentDisposition;
    disposition.CreationDate = System.IO.File.GetCreationTime(file);
    disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
    disposition.ReadDate = System.IO.File.GetLastAccessTime(file);
    // Add the file attachment to this e-mail message.
    message.Attachments.Add(data);

    //Send the message.
    SmtpClient client = new SmtpClient(server);
    // Add credentials if the SMTP server requires them.
    client.Credentials = CredentialCache.DefaultNetworkCredentials;

    try 
    {
      client.Send(message);
    }
    catch (Exception ex) 
    {
      Console.WriteLine("Exception caught in CreateMessageWithAttachment(): {0}", ex.ToString());              
    }
    data.Dispose();
}