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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TIP- Launch default e-mail Client with recipeint address 2

Status
Not open for further replies.

MissouriTiger

Programmer
Oct 10, 2000
185
US
I found this on the web and want to share it. Worked like a charm! A demo is posted at the following address (look for link at bottom of the web page):

Launch e-mail Client -This tip will show you how to launch the default e-mail client.

Declarations:

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


Function Code:

Function LaunchEmail(email As String, Form As Form) As Boolean

Dim ReturnVal As Long

ReturnVal = ShellExecute(Form.hwnd, "open", "mailto:" & email, "", App.Path, 0)

If ReturnVal < 31 Then 'Error

MsgBox &quot;There was a problem executing the default e-mail client. Check that it is properly installed.&quot;, vbInformation, App.Title

LaunchEmail = False

Else If ReturnVal = 32 Then 'Error

MsgBox &quot;There no file association for an e-mail client.&quot;, vbInformation, App.Title

LaunchEmail = False

Else 'Everything Worked
LaunchEmail = True

End If
End Function


Use:

Dim RetVal As BooleanRetVal = LaunchEmail(&quot;tom@vbland.hypermart.net&quot;, Me)
 
Hi,
Looks good... but I found the MAPI controls to be very robust - is there a reason that you didn't use them?

Rob Marriott
rob@career-connections.net
 
Glad you asked. Several reasons:

1. I found this code first and had already incorporated it into my project.

2. This is for a college project, but is above and beyond the actual requirements. The whole e-mail thing was just for my own satisfaction. I wanted the user to be able to click an employee in my flexgrid, and select &quot;send email&quot; from a popup menu. This code is pretty much tailor made for such an application.

3. Your code appears to require the programmer to know in advance which e-mail client is installed. To be frank, I don't even know for sure what computer my instructor will be using when he installs my program. I needed a way to generically call the default mail client regardless.

4. Since I have only been writing code since May, I am very green. Your code was more difficult for me to understand. What does MAPI mean?

5. You're code looks like it is designed for someone who has a specific message to send out. That wasn't my intention. I don't have a message parameter to pass, nor an e-mail program parameter (as I explained above). The only prarmeter I know at design time is the e=mail address of the recipient. Well, not really, but it'll be saved to a variable when the user clicks a row in the grid.

I really appreciate your help. I really like VB. Unfortuantely, next quarter I'll have to change lanes and take Java & ASP, which will likely keep me too busy to delve deeper into VB. And I was just really beginning to sink my teeth into it. Fortunately, in the spring I will take a COM class.

If you don't mind, would you tell me a bit about the kind of development you are doing? Also, if you care to explain the relative advantages of your MAPI method, I'm all ears.



 
With MS Exchange or Outlook, I had to also find out the default profile when multiple profiles existed. I did the following

'Retrieve the default profile from the registry
ProfileName = GetString(HKEY_CURRENT_USER, _ &quot;Software\Microsoft\Windows Messaging Subsystem\Profiles&quot; _ ,&quot;DefaultProfile&quot;)

'When a Messaging Profile exists, .UserName is the Profile name
MAPISes.UserName = ProfileName
MAPISes.SignOn
 
This discussion sounds like just what I need, if it can be applied to Visual Basic for Applications (i.e. Excel). Here is a post I made before I noticed this thread:

I use an Excel spreadsheet as a client and product management system. One
of the things I do with it (via Visual Basic and macros) is to format an email
and copy it to the Clipboard. I can then open Eudora (the default e-mail client), select &quot;New Message&quot; and paste the pre-formatted email -- then I'm ready to go except for the Mailto: and Subject: lines. I handle this by formatting them as the first two lines
in the e-mail, which I then Cut and Paste into the appropriate spots.

My question is: Is there any way to accomplish any (or all) of these steps
automatically? i.e. send the formatted email to Eudora, with the subject and
recipient fields already filled in?

I do not want to replace Eudora in the process, because I want the outgoing
email available for review in the Eudora mailbox when the resulting incoming
answer comes back.

Some of the code shown above does not look like it's available in VBA. does VBA have an equivalent?

Roy
 
2 Line code :
Dim retval As String
retval = Shell(&quot;Start.exe mailto:vbg.be@vbgroup.nl&quot;)


Eric De Decker
vbg.be@vbgroup.nl

Licence And Copy Protection AxtiveX
Source CodeBook for the programmer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top