Éric Moreau
asked on
Mailto and attachments
In a particular application, I absolutely need to use the mailto: protocol to send e-mails.
Using the mailto: command, I can open a new message from the default e-mail application and give the TO, CC, BCC, BODY, SUBJECT without any problem with Outlook and Outlook Express.
When I try the ATTACH, it works with Outlook but not with OE. Somebody know why and how to fix the problem ?
Using the mailto: command, I can open a new message from the default e-mail application and give the TO, CC, BCC, BODY, SUBJECT without any problem with Outlook and Outlook Express.
When I try the ATTACH, it works with Outlook but not with OE. Somebody know why and how to fix the problem ?
Seems like I read somewhere that OE doesn't support the attach param. Sounded kinda fishy to me so don't take my word for it...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
attachments are not text only. I have some Access database to send. Do you have a more specific address for the RFC ?
It seems most programmers use vbSendmail.dll from:
http://www.freevbcode.com/ShowCode.Asp?ID=109
I'll check for RFC, but basically it defines "3 to 4" mapping of ASCII characters to display binary data.
http://www.freevbcode.com/ShowCode.Asp?ID=109
I'll check for RFC, but basically it defines "3 to 4" mapping of ASCII characters to display binary data.
ASKER
I use vbSendMail every day but in this particular project, I can't!!!
ASKER
I can't even use the standard Winsock!
I have seen better explanation somewhere, but here is the RFC
http://www.faqs.org/rfcs/rfc1521.html
5.2. Base64 Content-Transfer-Encoding
- you can use only EncodeBase64Byte() and EncodeBase64String() from clsSendMail to do the conversion.
I didn't try it, I used only txt attachments, as in mentioned PAQ
http://www.faqs.org/rfcs/rfc1521.html
5.2. Base64 Content-Transfer-Encoding
- you can use only EncodeBase64Byte() and EncodeBase64String() from clsSendMail to do the conversion.
I didn't try it, I used only txt attachments, as in mentioned PAQ
If all fails, use this Quick Temporary Solution I use to send daily reports:
' Form1
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd _
As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As _
String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Sub Form_Click()
Dim ret As Long, tmpfilename As String, mailInfo(0 To 4) As String
mailInfo(0) = "aaa@aaa"
mailInfo(3) = "Report for %D"
mailInfo(4) = "Hi, I'm sending report for %D. Regards, "
tmpfilename = "c:\autoexec.bat"
' open folder with pre-selected file (qid=10874601, thanks KDivad)
ret = Shell("explorer """ & tmpfilename & """,/select", vbNormalNoFocus)
' open 'new message' in OE
ret = ShellExecute(Me.hwnd, vbNullString, _
"mailto:" & mailInfo(0) _
& "?CC=" & mailInfo(1) _
& "&BCC=" & mailInfo(2) _
& "&Subject=" & Replace(mailInfo(3), "%D", Format(Date, "dd.mm.yyyy") & _
" (" & WeekdayName(Weekday(Date, vbMonday), , vbMonday) & ")") _
& "&Body=" & Replace(mailInfo(4), "%D", Format(Date, "dd.mm.yyyy") & _
" (" & WeekdayName(Weekday(Date, vbMonday), , vbMonday) & ")") _
, vbNullString, "c:\", 1)
' user drags selected file onto the OE New message, and presses Ctrl+Enter
End Sub
' Form1
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd _
As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As _
String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Sub Form_Click()
Dim ret As Long, tmpfilename As String, mailInfo(0 To 4) As String
mailInfo(0) = "aaa@aaa"
mailInfo(3) = "Report for %D"
mailInfo(4) = "Hi, I'm sending report for %D. Regards, "
tmpfilename = "c:\autoexec.bat"
' open folder with pre-selected file (qid=10874601, thanks KDivad)
ret = Shell("explorer """ & tmpfilename & """,/select", vbNormalNoFocus)
' open 'new message' in OE
ret = ShellExecute(Me.hwnd, vbNullString, _
"mailto:" & mailInfo(0) _
& "?CC=" & mailInfo(1) _
& "&BCC=" & mailInfo(2) _
& "&Subject=" & Replace(mailInfo(3), "%D", Format(Date, "dd.mm.yyyy") & _
" (" & WeekdayName(Weekday(Date, vbMonday), , vbMonday) & ")") _
& "&Body=" & Replace(mailInfo(4), "%D", Format(Date, "dd.mm.yyyy") & _
" (" & WeekdayName(Weekday(Date, vbMonday), , vbMonday) & ")") _
, vbNullString, "c:\", 1)
' user drags selected file onto the OE New message, and presses Ctrl+Enter
End Sub
Eric I think you will have to use ameba's workaround. I read this information only a day or so ago and will try to find the link for you. As has been stated earlier, OE does not support the attach parameter in any way.
It is possible to create .eml file by modifying code for text-only attachments:
Print #numfile%, "Content-Type: text/plain;"
Print #numfile%, vbTab & "charset=""" & charset & """"
Print #numfile%, "Content-Transfer-Encoding : 7bit"
to some other values for Content-Type and Encoding.
Instead of simple text:
' write invoice data to file
Print #numfile%, "Invoice"
Print #numfile%,
Print #numfile%, "No: " & vbTab & "101/99"
file should be read and converted to text by using EncodeBase64-functions.
But, it requires many tests, studying RFC and .eml files...
Print #numfile%, "Content-Type: text/plain;"
Print #numfile%, vbTab & "charset=""" & charset & """"
Print #numfile%, "Content-Transfer-Encoding
to some other values for Content-Type and Encoding.
Instead of simple text:
' write invoice data to file
Print #numfile%, "Invoice"
Print #numfile%,
Print #numfile%, "No: " & vbTab & "101/99"
file should be read and converted to text by using EncodeBase64-functions.
But, it requires many tests, studying RFC and .eml files...
ASKER
I will need sometimes to test it. Don't be afraid if I don't come back on this question before a week (but I'll be back).
Meanwhile, if you have anything else, do not hesitate and post it.
I will open the vbSendMail code to try to get the EncodeBase64-functions (unless you have better suggestions).
Meanwhile, if you have anything else, do not hesitate and post it.
I will open the vbSendMail code to try to get the EncodeBase64-functions (unless you have better suggestions).
I attached an icon to a new message, and used File, Save As, and here is Subject.eml file:
From: "Bruno" <NOSPAM_bruno.paris@zg.hin et.hr>
To: "B.P." <NOSPAM_ameba@zg.tel.hr>
Subject: Subject
Date: Fri, 18 Jan 2002 18:07:49 +0100
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_NextPart_0 00_01DC_01 C1A04B.105 9DA80"
X-Priority: 3
X-MSMail-Priority: Normal
X-Unsent: 1
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
This is a multi-part message in MIME format.
------=_NextPart_000_01DC_ 01C1A04B.1 059DA80
Content-Type: text/plain;
charset="iso-8859-2"
Content-Transfer-Encoding: 7bit
Body
------=_NextPart_000_01DC_ 01C1A04B.1 059DA80
Content-Type: image/x-icon;
name="ICON1.ICO"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="ICON1.ICO"
AAABAAEAICAQAAAAAADoAgAAFg AAACgAAAAg AAAAQAAAAA EABAAAAAAA gAIAAAAAAA AAAAAAAAAA
AAAAAAAAAAAAAACAAACAAAAAgI AAgAAAAIAA gACAgAAAwM DAAICAgAAA AP8AAP8AAA D//wD/AAAA
/wD/AP//AAD///8AAAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAEAAAA
AAAAAwAAAAAAAAAATBmZmZEAAD d3d3AAAAAA BMwZmZmZEA P7u7twIAAA AEzMGZmZmZ EHu7u7cKIA
AATMxBmZmZmZEDu7u3CqIABMzE AZmZmZmZED u7twqqIATM QAGZmZmZmZ EDu7cKqqIC BAAAGZmZmZ
mZEDtwAqqiAiAAAAGZmZmZmZEH AAAqogKiAA AAGZmZmZmZ EAAAAqICqi AAA3GZmZmZ mZEAAAAiAq
qiAD+3GZmZmZmZEAAEwgKqqiD7 u3GZmZmZmZ EATMwAKqqg +7u3GZmZmZ mRBMzEAAKq oPu7u3GZmZ
mZkQzMQAAAKqD7u7u3GZmZmZEM xAAAAAKg+7 u7cAGZmZmR DEAAAAAAIP //9wAAGZmZ kQQAAAAAAA
MzMzMAAAEREREAAAAAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA
AAAAAAAAAAAAAAD/////////// ////////// ////////// /4A+A/8AHA H+AAgA/AAA AHgAAAAwAA
AAEEAAAADgAAQB8AAOAPgAHwBw AA+AIAAHAA AAAggAAAAM AAAAHgAAAD 8AEAB/gDgA /8B8Af////
////////////////////////// ///////w==
------=_NextPart_000_01DC_ 01C1A04B.1 059DA80--
From: "Bruno" <NOSPAM_bruno.paris@zg.hin
To: "B.P." <NOSPAM_ameba@zg.tel.hr>
Subject: Subject
Date: Fri, 18 Jan 2002 18:07:49 +0100
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_NextPart_0
X-Priority: 3
X-MSMail-Priority: Normal
X-Unsent: 1
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
This is a multi-part message in MIME format.
------=_NextPart_000_01DC_
Content-Type: text/plain;
charset="iso-8859-2"
Content-Transfer-Encoding:
Body
------=_NextPart_000_01DC_
Content-Type: image/x-icon;
name="ICON1.ICO"
Content-Transfer-Encoding:
Content-Disposition: attachment;
filename="ICON1.ICO"
AAABAAEAICAQAAAAAADoAgAAFg
AAAAAAAAAAAAAACAAACAAAAAgI
/wD/AP//AAD///8AAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAwAAAAAAAAAATBmZmZEAAD
AATMxBmZmZmZEDu7u3CqIABMzE
mZEDtwAqqiAiAAAAGZmZmZmZEH
qiAD+3GZmZmZmZEAAEwgKqqiD7
mZkQzMQAAAKqD7u7u3GZmZmZEM
MzMzMAAAEREREAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAD///////////
AAEEAAAADgAAQB8AAOAPgAHwBw
//////////////////////////
------=_NextPart_000_01DC_
>EncodeBase64-functions (unless you have better suggestions).
If vb is too slow, maybe you can use C++
http://support.microsoft.com/default.aspx?scid=kb;NL;q191239
(also some info on padding)
If vb is too slow, maybe you can use C++
http://support.microsoft.com/default.aspx?scid=kb;NL;q191239
(also some info on padding)
Also, threre are plenty of Base64 encode at www.planet-source-code.com
ASKER
Before loosing time with Base64 encoding procedures, can you ensure me that I will be able to open an Outlook Express "Create Message" form with the encoded file as an attachment ?
Here, ".eml" extension is registered as "Outlook Express Mail Message" by OE.
ret = ShellExecute(Me.hwnd, "Open", _
"FileName.EML", "", "c:\", SW_SHOWNORMAL)
You can use FindExecutable to check if there is no association, see:
http://www.mvps.org/vbnet/index.html?code/system/findexecutable.htm
This line signals OE it is new message (draft):
X-Unsent: 1
I think other e-mail programs understand that standard RFC file format.
ret = ShellExecute(Me.hwnd, "Open", _
"FileName.EML", "", "c:\", SW_SHOWNORMAL)
You can use FindExecutable to check if there is no association, see:
http://www.mvps.org/vbnet/index.html?code/system/findexecutable.htm
This line signals OE it is new message (draft):
X-Unsent: 1
I think other e-mail programs understand that standard RFC file format.
ASKER
Thanks ameba. I finally did it using your frmSendMail and some base64 encoding procedure found somewhere on Planet Source Code.
Thanks again.
Thanks again.
Great! Thank you!
how to open default mail client with excel file as attachment using javascript,html or java
Javascript and Java have their own TA, posting the question there should be more efficient for you.