Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

e-mail Using VB6 1

Status
Not open for further replies.

maxflitom

Programmer
Aug 26, 2002
70
US
Hello Tek-Tips,

I wish to add functonality to my app which will allow the user to send an e-mail using their default e-mail client, will place the subject in the subject line, e-mail recipitant, file attachment, and e-mail body letter. I wish to "Shell" the e-mail client app and have the user confirm and add the the "New Message" before sending.

I have searched the archives. The Shell("mailto:email@email.com") tells me that the file was not found. I am not sure if the MAPI control can display the default user's "New Message" from their client.

What is the most efficient way of accomplishing this task?

Thank you for any suggestions.

Tom

Tom (maxflitom)
 
This should get you started:

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 Command1_Click()
Dim strAddress As String
Dim strOpen As Long

strAddress = "mailto:somebody@somedomain.com"
strOpen = ShellExecute(Me.hwnd, "Open", strAddress, "", "", vbNormalFocus)
End Sub
 
If you wish to insert subject and body:

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 Command1_Click()
Dim strAddress As String
Dim strOpen As Long

strAddress = "mailto:somebody@somedomain.com?subject=Email Subject&body=Message Text"
strOpen = ShellExecute(Me.hwnd, "Open", strAddress, "", "", vbNormalFocus)
End Sub
 
To CC and BCC like this:

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 Command1_Click()
Dim strAddress As String
Dim strOpen As Long

strAddress = "mailto:somebody@somedomain.com?subject=EmailSubject &cc=somebody@somedomain.com &bcc=somebody@somedomain.com &body=Message Text"
strOpen = ShellExecute(Me.hwnd, "Open", strAddress, "", "", vbNormalFocus)
End Sub
 
maxflitom,

>>the file was not found<<

The Mailto string is limited to around 250 chars under W95 and 500 chars in later versions. If you exceed this you get the above error.

Mailto doesn't support adding attachments.

Paul Bent
Northwind IT Systems
 
My bad, I didn't notice the File Attachment part.
 
>Mailto doesn't support adding attachments

It's not the Mailto that is the issue; it is the resolver of the URL (your default email program). Most Microsoft email programs will not resolve 'attachment'. Software from other vendors may do (I seem to recall that Lotus Notes does)
 
>>It's not the Mailto that is the issue<<

I beg to differ. Mailto is specified in RFC2368. The specification does not support attachments.

>>Software from other vendors may do<<

If so, that's a proprietory implementation of Mailto and in any case, wouldn't fulfil maxfiltom's requirements of working with whatever is the default e-mail program.


Paul Bent
Northwind IT Systems
 
>wouldn't fulfil maxfiltom's requirements

Never said it did. I was merely arguing with the assertion that mailto doesn't support attachments, which is incorrect. It is not mailto (which is merely a URL) that is the issue, it is the resolver (in current practice generally one's default email program)

I'm aware of RFC2368, and there is nothing in that RFC that prohibits the use of whatever headers you like;'wombat', 'stickytoffeepudding','whateveryoulike' would all be legitimate as long as they followed RFC 822 conventions concerning encoding of headers and their values. Indeed the whole point of the RFC was to extend earlier RFCs (in particular RFC1738) so that additional headers could be legitimately included in the Mailto URL. The headers can be whatever you like.

The only thing the RFC says (apart from warnings about what are considered 'safe' headers - and I'd point out that 'cc' and 'bcc' are considered unsafe), is that, apart from the recipient, you can only expect a resolver to support the &quot;subject&quot; and &quot;body&quot; headers, i.e those two headers are what a resolver must support - but they are not actually limited to support only those headers.

To summarise:

1. RFC2368 does not specify any email protocol whatsoever; it defines a URL format
2. It is the resolver of the URL which decides which headers to act on (or not) and how to interpret them. Indeed, the RFC specifically states that how the Mailto URL is resolved &quot;is not mandated&quot; by the RFC's URL specifications
3. At a bare minimum, a resolver must understand the &quot;subject&quot; and &quot;body&quot; headers, but this does not preclude it from resolving any others it fancies

Therefore the point I was making, and continue to make, that it is a feature of your resolver, not of Mailto, whether it deals with the 'attachment' header or not
 
Thank you everyone for the helpful suggestions. I will give them all a try.

Tom

Tom (maxflitom)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top