Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Mailto and attachments

Posted on 2002-01-17
20
Medium Priority
?
9,986 Views
Last Modified: 2008-02-26
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 ?
0
Comment
Question by:Éric Moreau
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 6
  • 2
  • +3
20 Comments
 
LVL 5

Expert Comment

by:KDivad
ID: 6740043
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...
0
 
LVL 15

Accepted Solution

by:
ameba earned 800 total points
ID: 6740050
MS Outlook uses MAPI, which supports attachments.

For OE, it is possible to create .eml file which can hold one or more simple text attachments.
see SendMail.Frm in http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=10154671

To attach binary file (e.g. excel file) you must use some encoding, e.g. "base64" - specifications can be found in some RFC.
0
 
LVL 70

Author Comment

by:Éric Moreau
ID: 6740065
attachments are not text only. I have some Access database to send. Do you have a more specific address for the RFC ?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 15

Expert Comment

by:ameba
ID: 6740074
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.
0
 
LVL 70

Author Comment

by:Éric Moreau
ID: 6740077
I use vbSendMail every day but in this particular project, I can't!!!
0
 
LVL 70

Author Comment

by:Éric Moreau
ID: 6740078
I can't even use the standard Winsock!
0
 
LVL 15

Expert Comment

by:ameba
ID: 6740093
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
0
 
LVL 15

Expert Comment

by:ameba
ID: 6740202
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
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6741204
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.
0
 
LVL 15

Expert Comment

by:ameba
ID: 6741287
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...
0
 
LVL 70

Author Comment

by:Éric Moreau
ID: 6741300
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).
0
 
LVL 15

Expert Comment

by:ameba
ID: 6741397
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--
0
 
LVL 15

Expert Comment

by:ameba
ID: 6741425
>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)
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6744496
Also, threre are plenty of Base64 encode at www.planet-source-code.com
0
 
LVL 70

Author Comment

by:Éric Moreau
ID: 6745479
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 ?
0
 
LVL 15

Expert Comment

by:ameba
ID: 6745649
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.
0
 
LVL 70

Author Comment

by:Éric Moreau
ID: 6752634
Thanks ameba. I finally did it using your frmSendMail and some base64 encoding procedure found somewhere on Planet Source Code.

Thanks again.
0
 
LVL 15

Expert Comment

by:ameba
ID: 6752942
Great! Thank you!
0
 

Expert Comment

by:gopinathb4u
ID: 11060025
how to open default mail client with excel file as attachment using javascript,html or java
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 11061504
Javascript and Java have their own TA, posting the question there should be more efficient for you.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question