Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add attachments to mailto in c#?

Tags:

c#

unity3d

string email ="[email protected]";
attachment = path + "/" + filename;
Application.OpenURL ("mailto:" + 
                      email+"
                      ?subject=EmailSubject&body=EmailBody"+"&attachment="+attachment);

In the above code, attachment isn't working. Is there any other alternative to add attachments using a mailto: link in C#?

like image 636
vicky Avatar asked Dec 24 '15 06:12

vicky


2 Answers

mailto: doesn't officially support attachments. I've heard Outlook 2003 will work with this syntax:

<a href='mailto:[email protected]?Subject=SubjTxt&Body=Bod_Txt&Attachment=""C:\file.txt"" '>

Your problem has already been answered: c-sharp-mailto-with-attachment

like image 82
Max Sassen Avatar answered Sep 21 '22 18:09

Max Sassen


You can use the System.Net.Mail which has the MailMessage.Attachments Property. Something like:

message.Attachments.Add(new Attachment(yourAttachmentPath));

OR

You can try like this:

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("[email protected]");
            mapi.AddRecipientTo("[email protected]");
            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");
        }
    }
}

The above code uses the MAPI32.dll.

Source

It probably won't attach the document because you are at the liberty of the email client to implement the mailto protocol and include parsing for the attachment clause. You may not know what mail client is installed on the PC, so it may not always work - Outlook certainly doesn't support attachments using mailto.

like image 31
Rahul Tripathi Avatar answered Sep 21 '22 18:09

Rahul Tripathi