Link to home
Start Free TrialLog in
Avatar of Éric Moreau
Éric MoreauFlag for Canada

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 ?
Avatar of KDivad
KDivad

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
Avatar of ameba
ameba
Flag of Croatia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Éric Moreau

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.
I use vbSendMail every day but in this particular project, I can't!!!
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
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
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...
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).
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.hinet.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_000_01DC_01C1A04B.1059DA80"
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.1059DA80
Content-Type: text/plain;
     charset="iso-8859-2"
Content-Transfer-Encoding: 7bit

Body


------=_NextPart_000_01DC_01C1A04B.1059DA80
Content-Type: image/x-icon;
     name="ICON1.ICO"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
     filename="ICON1.ICO"

AAABAAEAICAQAAAAAADoAgAAFgAAACgAAAAgAAAAQAAAAAEABAAAAAAAgAIAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAACAAACAAAAAgIAAgAAAAIAAgACAgAAAwMDAAICAgAAAAP8AAP8AAAD//wD/AAAA
/wD/AP//AAD///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAA
AAAAAwAAAAAAAAAATBmZmZEAADd3d3AAAAAABMwZmZmZEAP7u7twIAAAAEzMGZmZmZEHu7u7cKIA
AATMxBmZmZmZEDu7u3CqIABMzEAZmZmZmZEDu7twqqIATMQAGZmZmZmZEDu7cKqqICBAAAGZmZmZ
mZEDtwAqqiAiAAAAGZmZmZmZEHAAAqogKiAAAAGZmZmZmZEAAAAqICqiAAA3GZmZmZmZEAAAAiAq
qiAD+3GZmZmZmZEAAEwgKqqiD7u3GZmZmZmZEATMwAKqqg+7u3GZmZmZmRBMzEAAKqoPu7u3GZmZ
mZkQzMQAAAKqD7u7u3GZmZmZEMxAAAAAKg+7u7cAGZmZmRDEAAAAAAIP//9wAAGZmZkQQAAAAAAA
MzMzMAAAEREREAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAD////////////////////////////////4A+A/8AHAH+AAgA/AAAAHgAAAAwAA
AAEEAAAADgAAQB8AAOAPgAHwBwAA+AIAAHAAAAAggAAAAMAAAAHgAAAD8AEAB/gDgA/8B8Af////
/////////////////////////////////w==

------=_NextPart_000_01DC_01C1A04B.1059DA80--
>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)
Also, threre are plenty of Base64 encode at www.planet-source-code.com
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.
Thanks ameba. I finally did it using your frmSendMail and some base64 encoding procedure found somewhere on Planet Source Code.

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.