Link to home
Start Free TrialLog in
Avatar of billcute
billcute

asked on

Using Widows MAPI to Launch Yahoo Mail or Gmail

I have a combo with "Yes" and "No" value with a question users will see before selecting the "Yes" or "No" answer,

       Question                                                  Combo11.value
Do you have a Web Based e-mail?                        (Yes / No)

If the user select "Yes", then the code below is expected to offer Windows based "MAPI". The code is expected to launch "yahoo" or "gmail" wherby users can send e-mail via the "provider"

If the User selects "No", then the code is expected to DoCmd.OpenForm "frmExampleMail" which will be saved in WordPad.

The "wordPad" format works fine but the e-mail portion was launching "OutlookMail". How do I modify the code below to launch "YahooMail" or "Gmail" browser?


Private Sub Combo11_AfterUpdate()

Select Case Me.Combo11.Value
Case "Yes"
'// they use yahoo etc
Me.Combo7.Visible = False
Me.Combo9.Visible = False
Me.Command4.SetFocus
Me.Combo11.Visible = False
'DoCmd.OpenForm "frmExampleEmail", , , , , , Me.OpenArgs
Command = "Mail"
Case "No"
'// Nope so search for any other default email clients
'// Mail Me.OpenArgs
Command = "ExampleEmail"
Case Else
'// Incorrect value
MsgBox "An incorrect value was selected, Please try again."
End Select
End Sub
Avatar of dannywareham
dannywareham
Flag of United Kingdom of Great Britain and Northern Ireland image

I'm not 100% about this, but I don't think that MAPI would work witha web-based mail provider.
Instead, I think that you'd have to shell out to IExplorer and open the webpage for the user...

As I said, I'm not 100% sure though...

:-)
Avatar of Billystyx
Billystyx

Application.FollowHyperlink "http://www.yahoo.com", _
    , , , , msoMethodGet
this will launch your default browser and open to the address
billystyx
Avatar of bluelizard
my suggestion: use the API from here: http://www.mvps.org/access/api/api0018.htm.  this is code you simply paste into a new module.  afterwards, you can open any document or link as follows:

'***************Usage Examples***********************
'Open a folder:     ?fHandleFile("C:\TEMP\",WIN_NORMAL)
'Call Email app:    ?fHandleFile("mailto:dash10@hotmail.com",WIN_NORMAL)
'Open URL:          ?fHandleFile("http://home.att.net/~dashish", WIN_NORMAL)

so, instead of "Command = "Mail"", you write this line to open e.g. yahoo webmail:

   call fHandleFile("http://mail.yahoo.com/", WIN_NORMAL)

this will automatically use the user's default browser.  as you can see from the above usage examples, you can also launch the default *email* client with this code (in case your user doesn't have web mail).


--bluelizard
Avatar of billcute

ASKER

To All,
Since I would not know the user's default e-mail address, I will prefer a situation where the default "e-mail Client for each individual user could be launched with your suggested code.

I will appreciate it if you could post the correct code here in such a way that I wont get compile errors. Any help will be appreciated.
with the method i suggested (using the API from mvps.org), you simply write

   call fHandleFile("mailto:MyEmailRecipient@whatevermail.com",WIN_NORMAL)

to call the default email client (outlook, thunderbird, whatever) with the email address MyEmailRecipient@whatevermail.com already in the "To:" field.


--bluelizard
or, all of the code would be this:

Private Sub Combo11_AfterUpdate()

Select Case Me.Combo11.Value
Case "Yes"
'// they use yahoo etc
Me.Combo7.Visible = False
Me.Combo9.Visible = False
Me.Command4.SetFocus
Me.Combo11.Visible = False
call fHandleFile("http://mail.yahoo.com/", WIN_NORMAL)
Case "No"
'// Nope so search for any other default email clients
call fHandleFile("mailto:MyEmailRecipient@whatevermail.com",WIN_NORMAL)
Case Else
'// Incorrect value
MsgBox "An incorrect value was selected, Please try again."
End Select
End Sub


--bluelizard
Pertaining to this line code: call fHandleFile("http://mail.yahoo.com/", WIN_NORMAL)

I tested this and it launched yahoo mail automatically. But my point is , I would prefer the code to look for the approriate default e-mail and launch it without having to specify any provider like yahoo gmail..I a particular provider is specified, there is the tendency that the code will launch that first as it did with my test. So a revised code will be appreciated.
Keep the e-mail url in a table then use DLOOKUP:

Dim myMail as String
myMail = DLOOKUP("mail", "yourtable", "Username = " & chr(34) & environ("username") & chr(34))
call fHandleFile(myMail, WIN_NORMAL)


when you write "default e-mail", do you mean the email client *installed on the local machine* (e.g., outlook etc.), or do you mean the user's default *web* based email (yahoo, gmail etc.)?

for the first one, you can use the line call fHandleFile("mailto:MyEmailRecipient@whatevermail.com",WIN_NORMAL)

for the latter, you need to know from somewhere what the user's default web based email service is, as i don't think it is reliably stored somewhere on the PC (maybe you could search through the cookies etc., but i doubt that his is reliable, as users can remove cookies etc.).  you could either add a field to the user table (if you have one) where you store the URL of their default webmail service, or could add a set of radio buttons to your form that lets the user pick one of the usual ones.  then, when you open the webmail service, check the status of the radio buttons and call the appropriate website:

  select case me.frameWebmailService
    case 0:
      call fHandleFile("http://mail.yahoo.com/", WIN_NORMAL)
    case 1:
      call fHandleFile("http://gmail.com/", WIN_NORMAL)
   end select


--bluelizard
I will like to explore this but I dont know how since I dont have any User table for that purpose but would be glad to create one in order to experiment your suggestion.
Create a table of users:

UserID: AutoNumber
UserName: Text name of user
UserLogIn: Computer name
ExtMailAdd: Text of web mail address
IntMailAdd: Text of internal mail address


Then, you can use the function    Environ("Username") to return teh computer login name, and match this to the table to return the mail address:

Dim myMail as String
If msgbox ("Do you want to use your internal mail?", vbYesNoCancel, "Send Mail") = vbYes Then
     myMail = DLOOKUP("IntMailAdd", "yourtable", "UserLogIn = " & chr(34) & environ("username") & chr(34))
     call fHandleFile(myMail, WIN_NORMAL)
Else If vbNo Then
     myMail = DLOOKUP("ExtMailAdd", "yourtable", "UserLogIn = " & chr(34) & environ("username") & chr(34))
     call fHandleFile(myMail, WIN_NORMAL)
Else If vbCancel
     msgbox "Cancelled", vbokonly, "Mail Not Sent"
End If

To All,
Based on the last two suggested posts from "Dan" and "blueLizard", I have come up with the description below in order to experiment the two suggestions in one shot.

I just remember that I have a table I use for login in into an Application. I really dont want something fanciful, I just want to be able to use the table without having to log in to any Application and without requesting UserName and password. But I can use the table (tblUsers) that contain Fname, LName, txtEmailAddress1, txtEmailAddress2 and txtEmailAddress3.

"frmAddNewEmail", is bounded to tblUsers and the other form
"frmSelectContactMethod" is not bounded to any table but can be used for "DLookUp" functions with my codes behind it.

"frmSelectContactMethod" is the form I want users to use to connect to the user's e-mail while frmAddNewEmail will be used to add new e-mails up to 3 different e-mails.

"frmSelectContactMethod" will have new (combo, currently absent in my design) that will ask users to select the appropriate e-mail he wants to use out of the 3 e-mails in tblUsers.

I will like to experiment this where I could add 3 fields for e-mails such that users could enter multiple e-mails but could only use one he prefers using tblUsers

Here users could be asked in a "Question type" format to provide perhaps two or three Web Emails by typing them in the fields on a form bounded to tblUsers; and then pose another question to the in next combo to select from the list of e-mails to use.

Please select the appropriate default e-mail you'll like to use.(The user will have a dropdown combo where he could select any of the e-mail service he has just typed in.

Next time the user wants to log in again, the e-mails are already there and he could still modify them as he likes.

Here, the users will have the option to select one e-mail service he wants to use and the next screen will just open the URL to that mail.

I really dont want users to log in with any password though, I just want a simple function with the e-emails

I am open to other suggestions.

Regards
Bill
if this app will run on windows NT, 2000, XP or higher (anyway: an OS where the user has a login name), you can use environ("username"), as dannywareham suggested above.  this way, there's no need to log into the application.


--bluelizard
ASKER CERTIFIED SOLUTION
Avatar of dannywareham
dannywareham
Flag of United Kingdom of Great Britain and Northern Ireland 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
Dan,
This works very well. Thanks for your assistance.
ahem... may i remind you that part of the solution you're using now was suggested by me? (see 3rd post).  i guess it would have been appropriate to split the points at least a little bit...


--bluelizard
bluelizard,
When I read your comment dated: 05/09/2005 09:05AM EDT, my impression was that you were in support for me to use Dan's method and code.

BlueLizard wrote:
--- if this app will run on windows NT, 2000, XP or higher (anyway: an OS where the user has a login name), you can use environ("username"), as dannywareham suggested above.  this way, there's no need to log into the application.

If any of your code was used I did not know but I'll make it up to you some other time - sorry for the mix up.

Bill
actually, i was referring to this post:

>my suggestion: use the API from here: http://www.mvps.org/access/api/api0018.htm.  this is code you simply paste into a new module.  afterwards, you can open any document or link as follows:
>
>'***************Usage Examples***********************
>'Open a folder:     ?fHandleFile("C:\TEMP\",WIN_NORMAL)
>'Call Email app:    ?fHandleFile("mailto:dash10@hotmail.com",WIN_NORMAL)
>'Open URL:          ?fHandleFile("http://home.att.net/~dashish", WIN_NORMAL)
>
>so, instead of "Command = "Mail"", you write this line to open e.g. yahoo webmail:
>
>   call fHandleFile("http://mail.yahoo.com/", WIN_NORMAL)
>
>this will automatically use the user's default browser.  as you can see from the above usage examples, you can also launch the default *email* client with this code (in case your user doesn't have web mail).

but that's o.k., never mind...  ;-)


--bluelizard

bluelizard,
Okay, I see your point, hmmm...my fault, not to worry.