Page 1 of 1
revMail - include attached file
Posted: Mon Aug 04, 2008 7:07 pm
by rliefer
The revMail command needs to be able to add an attached file to the email. This is a FUNDAMENTAL capability when doing anything with email! Thanks.
Posted: Mon Aug 04, 2008 8:42 pm
by Garrett
Attachments to emails are actually encoded into the email itself in a text format. You would use base64 encoding to do this, and then put the resulting data into the email itself using the proper text data entries so that email clients know there's an attachment, where it is and where it ends.
check in the rev docs for base64Encode and base64Decode
Here's what an attachment looks like in a raw email:
Code: Select all
------=_NextPart_000_0553_01C7D1F8.61B9A740
Content-Type: application/x-zip-compressed;
name="somefile.zip"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="somefile.zip"
WV3LlJFRyWMvQqDMBgA90DeIXtbSaKpZvgGKbSditT+DKVD
kKBSTSR+Unz7Wlzvjnsd+0drv1dbtyMGg613b0ouprdwMiFYR
------=_NextPart_000_0553_01C7D1F8.61B9A740--
This is usually found after the text of the email, at the end of the email.
revMail - include attached file
Posted: Tue Aug 05, 2008 4:50 am
by rliefer
Hi Garrett,
Thanks for the info. I read up on the base64Encode function and am able to encode a text string and have it show up in the body of an email as base64 text gibberish. But how do I use base64Encode to get a file from my hard drive to show up in an email as an attached file? Thanks for your help.
Posted: Tue Aug 05, 2008 9:54 pm
by Garrett
Sorry, I'm just not quite fluent enough with Rev to give an immediate answer for you on that part.
A quick look in the docs brings up the "open file" command
Code: Select all
Syntax:
open file filePath [for [text | binary] {update | read | write | append}]
So I'd open a file as binary for read, then base64 encode that data. At least in my mind that seems to be what needs to be done. I could of course be wrong. But I believe that's all that needs to be done.. Seems about right, so hope it is.
Posted: Wed Aug 06, 2008 1:51 am
by SparkOut
You can open a file with the URL command, as in
Code: Select all
answer file "What file would you like to encode?"
put the base64Encode of url ("binfile:" & it) into tAttachment
You could then include it in a text structure which holds the header information and the MIME content boundaries. (That is not a trivial thing to get right.)
I am pretty sure that will not do you any good with using the revMail command. That will pop up a new message in the user's default mail program, and that would typically not consider a MIME encoded text file as anything but plain text. So you'd get nothing but base64 gobbledigook at the other end - I don't believe there is a way to append an attachment via revMail because of the cross-platform and cross-client possibilities, because almost all of them will prevent external clients from that degree of automation as a security measure. (Melissa virus was spread by an exploit of that sort, I believe, but that was an exploit.)
It is true that email attachments are just base64 encoded text files, but to send one, it's not going to be easy to get revMail to handle it. You would need to go to a lower level and pass the correctly bounded file to an SMTP server. If you create the correct file you can use Sarah Reichelt's SMTP library that Jan mentioned in the other thread, or there are a couple of other handy SMTP libraries, Chipp Walters altEmailHarness (based on Sean Shao's libSmtp) for instance. I forget where that is on his site - but I think you might find it on RevOnline.
Posted: Wed Aug 06, 2008 3:24 am
by Garrett
Good point.. I wasn't even paying attention that revMail was the main point of this, which only opens an already installed email client on the users system. My old brain just assumed he was doing this all via raw sockets or something. Yeah, check out those libs that he mentioned for actually sending the emails and attachments yourself instead of trying to rely on the client's own email program.