75

How can i send an email with an attachment (either local file or a file in the intranet) using outlook 2010?

<a href="mailto:a@gmail.com?subject=my report&body=see attachment&attachment=c:\myfolder\myfile.txt">

doesn't seem to work.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Benchik
  • 2,057
  • 5
  • 26
  • 44

4 Answers4

112

Nope, this is not possible at all. There is no provision for it in the mailto: protocol, and it would be a gaping security hole if it were possible.

The best idea to send a file, but have the client send the E-Mail that I can think of is:

  • Have the user choose a file
  • Upload the file to a server
  • Have the server return a random file name after upload
  • Build a mailto: link that contains the URL to the uploaded file in the message body
Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • In this case i could use apache commons i think. – Benchik Mar 08 '11 at 14:55
  • 1
    not bad, but there will be a place on the server where all the user files are located that will need cleaning from time to time somehow. Maybe [this approach would work for that](http://stackoverflow.com/questions/5760969/php-how-to-delete-a-file-from-server-after-is-read-unlink-is-executed-befor) – ejectamenta Nov 25 '14 at 18:24
  • 6
    Apparently Thunderbird and some other clients *did* support `?attach=...` until December 2019: https://www.nds.ruhr-uni-bochum.de/media/nds/veroeffentlichungen/2020/08/15/mailto-paper.pdf . But now it is removed, for the obvious reasons. – jpa Aug 18 '20 at 10:20
2

this is not possible in "mailto" function.

please go with server side coding(C#).make sure open vs in administrative permission.

Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem oMsg = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);

oMsg.Subject = "emailSubject";
oMsg.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML;
oMsg.BCC = "emailBcc";
oMsg.To = "emailRecipient";

string body = "emailMessage";

oMsg.HTMLBody = "body";              
oMsg.Attachments.Add(Convert.ToString(@"/my_location_virtual_path/myfile.txt"), Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);

oMsg.Display(false); //In order to displ
Boopathi.Indotnet
  • 1,280
  • 15
  • 18
  • i have tried with mailto function but its not possible, so i have tried above code to achieve that. – Boopathi.Indotnet Mar 02 '17 at 06:18
  • 2
    Isn't it [problematic](https://support.microsoft.com/en-us/help/257757/considerations-for-server-side-automation-of-office) using Microsoft Office automation on a server? – Zack Sep 05 '19 at 14:59
-1

If you are using c# on the desktop, you can use SimpleMapi. That way it will be sent using the default mail client, and the user has the option of reviewing the message before sending, just like mailto:.

To use it you add the Simple-MAPI.NET package (it's 13Kb), and run:

var mapi = new SimpleMapi();
mapi.AddRecipient(null, address, false);
mapi.Attach(path);
//mapi.Logon(ParentForm.Handle);    //not really necessary
mapi.Send(subject, body, true);
E_net4
  • 27,810
  • 13
  • 101
  • 139
AlexDev
  • 4,049
  • 31
  • 36
  • 4
    The question is tagged HTML. As far as I have seen Mapi cannot be used from a web page. See this link https://stackoverflow.com/questions/12234916/send-mail-using-default-webclient-in-asp-net-using-mapi-in-c-sharp-web-applicati – Dov Miller Feb 02 '20 at 14:00
  • 1
    @DovMiller Yes, it will only work for desktop apps. If you really need to open outlook from a web app you can try https://stackoverflow.com/questions/35229240/javascript-open-outlook-and-add-attachments-to-new-email . But if all you need is to send an email the link you sent has a much better solution. – AlexDev Feb 03 '20 at 09:45
-15

what about this

<FORM METHOD="post" ACTION="mailto:jburns@htmlgoodies.com" ENCTYPE="multipart/form-data">
Attachment: <INPUT TYPE="file" NAME="attachedfile" MAXLENGTH=50 ALLOW="text/*" >
 <input type="submit" name="submit" id="submit" value="Email"/>
</FORM>
John Smith
  • 215
  • 3
  • 4
  • 10
  • 8
    Tried it out on a jsfiddle... it just opens an email dialog and prefills the body with `attachedfile=filename.ext&submit=Email`. It doesn't attach any data. – Dan Fox Jun 03 '14 at 20:48
  • Works, The file referenced attach the file in the client – esdebon Nov 13 '19 at 01:48