Using Mailto to Send Email With an Attachment

using mailto to send email with an attachment

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

How to attach blob file into HTML href=mailto:

mailto: doesn't support attachments, but there are various ways you could achieve a similar effect:

  1. Link to the file in a message body

    You mentioned that the link needs authorisation, you could generate temporary urls that last 30 minutes (or more/less) which allow for downloads (users can then attach the file themselves)

  2. Send the email yourself

    Your service could send an email to your user (or on behalf of your user) with the attachment using something like Amazon SES, or Mailchimp, etc...

  3. Render your PDF into HTML

    It seems you are planning on attaching PDF files. Depending on the complexity of the PDF files, you could attempt to convert the PDF into email-friendly HTML using one of many tools, such as pdf2htmlEX or Pandoc.

Is it possible to add a attachment to a mail with the mailto function in actionscript 3?

From my understanding, using &attachment=file only works locally.\\host\path\to\file

Where as

does not work.

Attach File Through mailto URI

No, you can not add an attachment to a message with the mailto: URL scheme.

mailto: only supports header values or text/plain content. See RFC 2368 for details.

C# MailTo with Attachment?

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

<a href='""C:\file.txt"" '>

A better way to handle this is to send the mail on the server using System.Net.Mail.Attachment.

    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(
"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.

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

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

Related Topics

Leave a reply