Discussion:
mailto with attachment problem
(too old to reply)
Kenji Horvath
2004-04-23 15:16:26 UTC
Permalink
What i'm trying to do is programmatically bring up a new message for the
default mail client with an attachement already attached. I've successfully
been able to bring up a new message with an e-mail address, subject, and
body, but i can't attach a file no matter what i try. Some things seem to
have no effect, and others seem to cause outlook to bring up a messagebox
(Command line arguement is not valid). Here's some mailto: commands i've
tried using in shell execute

mailto:***@vt.edu?subject=my report&body=see
attachment&attachment="\\Gamingmachine\download temp\invoice.html"
mailto:***@vt.edu?subject=test&attachment=\\Workpc1\c$\DownloadTemp\redist.txt
mailto:***@vt.edu?subject=test&attachment="\\Workpc1\c$\DownloadTemp\redist.txt\"
mailto:***@vt.edu?subject=test?&attachment=\\Workpc1\c$\DownloadTemp\redist.txt
mailto:***@vt.edu?subject=test?&attachment="\\Workpc1\c$\DownloadTemp\redist.txt\"
mailto:***@vt.edu?subject=test?attachment=\\Workpc1\c$\DownloadTemp\redist.txt
mailto:***@vt.edu?subject=test?attachment="\\Workpc1\c$\DownloadTemp\redist.txt\"
mailto:***@vt.edu?subject=test&attachment="\\Workpc1\DownloadTemp\redist.txt\"
mailto:***@vt.edu?subject=test&attachment="c:\DownloadTemp\redist.txt"

Of course the format in my cpp file is
ShellExecute(NULL,"open","mailto:***@vt.edu?&attachment=\"c:\\redist.tx
t\"","","", SW_SHOW );

I've tried more but you get the idea that i've tweaked almost every aspect
of this but can never get an e-mail with the attachment to come up. I read
one article that said allowing attachments through mailto: is a security
risk so it doesn't work. Is this true?
I appreciate any information anyone can provide. Thank you very much in
advance.

Kenji Horvath
David Lowndes
2004-04-23 16:40:36 UTC
Permalink
Post by Kenji Horvath
...
I've tried more but you get the idea that i've tweaked almost every aspect
of this but can never get an e-mail with the attachment to come up. I read
one article that said allowing attachments through mailto: is a security
risk so it doesn't work. Is this true?
I don't know if that's the reason, but when I tried, I couldn't find
how to make mailto pass attachments.

If it's applicable for you, I'd use Simple MAPI - it's not that hard.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
Jerry Coffin
2004-04-24 16:14:51 UTC
Permalink
In article <***@4ax.com>,
***@example.invalid says...

[ ... ]
Post by David Lowndes
I don't know if that's the reason, but when I tried, I couldn't find
how to make mailto pass attachments.
In email, an attachment isn't a header, its a chunk of text in the
body of the email, preceded by some stuff to tell the receiving email
program how to decode it, and what to do with the data after it's
decoded. You do need to add one header that says this is a multi-
part/mixed email:

Content-type: multipart/mixed; boundary=yourdelimiter

Then in the body of the email, you use the delimiter given above to
delimit the various parts of the body:

--yourdelimiter
Content-Type: text/plain

This will show up as the body of the email.

--yourdelimiter
Content-Type: text/plain
Content-Disposition: attachment; filename="whatever.txt"

This will be received as an attachment saved in a file named
"whatever.txt".
--yourdelimiter--

The sequence: "--", your delimiter, "--" signals the end of the
message.

If you want to send a file containing non-printable characters, you
need to encode it with something like MIME, uuencode, etc. E.g.:

--yourdelimiter
Content-Type: application/octet-stream; name="somefile.zip"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="somefile.zip"

// MIME-encoded data here

--yourdelimiter--

The obvious problem with this is that with a mailto:, you have to put
the entire body of the message on the command line. Since the
attachment is part of the body, you have to put the _entire_ attached
file (after encoding, if appropriate) on the command line. The
command line is limited to something like 32K, so the total size of
all the headers, body, AND attached files (AFTER encoding, no less)
can't exceed that for a mailto: to be able to send it.

To summarize: using a mailto: to attach a file is a lot of work and
places such a severe limit on the size of attachments that it has (at
best) extremely limited applicability (I.e. it'll only work
dependably to send pre-selected files known to be well under the size
limit).
--
Later,
Jerry.

The universe is a figment of its own imagination.
David Lowndes
2004-04-25 14:41:53 UTC
Permalink
Thanks for the explanation Jerry.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
Gary Chang
2004-04-24 07:55:40 UTC
Permalink
Hi Kenji,

Do you mean the mailto: of the following doc:
http://msdn.microsoft.com/library/default.asp?url=/workshop/networking/prede
fined/mailto.asp

If so, it appears no "Attachment" like name-value in this protocal.


Thanks!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Continue reading on narkive:
Loading...