?
Solved

Using Widows MAPI to Launch Yahoo Mail or Gmail

Posted on 2005-05-09
19
Medium Priority
?
2,371 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:billcute
  • 7
  • 7
  • 4
  • +1
19 Comments
 
LVL 26

Expert Comment

by:dannywareham
ID: 13958111
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...

:-)
0
 
LVL 18

Expert Comment

by:Billystyx
ID: 13958113
Application.FollowHyperlink "http://www.yahoo.com", _
    , , , , msoMethodGet
this will launch your default browser and open to the address
billystyx
0
 
LVL 14

Expert Comment

by:bluelizard
ID: 13958126
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
0
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
LVL 4

Author Comment

by:billcute
ID: 13958175
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.
0
 
LVL 14

Expert Comment

by:bluelizard
ID: 13958190
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
0
 
LVL 14

Expert Comment

by:bluelizard
ID: 13958192
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
0
 
LVL 4

Author Comment

by:billcute
ID: 13958243
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.
0
 
LVL 26

Expert Comment

by:dannywareham
ID: 13958302
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)


0
 
LVL 14

Expert Comment

by:bluelizard
ID: 13958309
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
0
 
LVL 4

Author Comment

by:billcute
ID: 13958454
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.
0
 
LVL 26

Expert Comment

by:dannywareham
ID: 13958502
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

0
 
LVL 4

Author Comment

by:billcute
ID: 13959033
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
0
 
LVL 14

Expert Comment

by:bluelizard
ID: 13959084
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
0
 
LVL 26

Accepted Solution

by:
dannywareham earned 2000 total points
ID: 13959502
Bill,
I've replied to your mail with an example.

The coding is virutally identical to what's here.

For those playing along at home, this is what I've used in the form (the module from above is also used):

Option Compare Database
Option Explicit
Private myStatus As Integer
'--------------------------------------------------------
Private Sub cboMyCombo_AfterUpdate()
On Error GoTo Errtrap
Dim myCaption As String
Dim myRecordSource As String
Dim myType As String
Dim myMail As String

Select Case myStatus
 Case 1         'form is just opened. Show first question
    If Me.cboMyCombo = "No" Then
        MsgBox "You need an internet connection", vbOKOnly, "Mail Query"
        Exit Sub
    End If
    myStatus = 2
    Me.cboMyCombo = ""
    myCaption = "Is Microsoft Outlook your default email client?"
    myRecordSource = """Yes""; ""No"""
   
 Case 2          '1st question has been asked, show next question
    myCaption = "Do you have a web-based email account?" & vbCrLf & "(eg. such as Yahoo, Hotmail, Gmail)"
    myRecordSource = """Yes""; ""No"""
    If Me.cboMyCombo = "Yes" Then
        'send mail with outlook
        myType = "Outlook"
    End If
    myStatus = 3
    Me.cboMyCombo = ""
   
 Case 3         '2nd question has been asked - ask 3rd
        If Me.cboMyCombo = "Yes" Then
            'send mail with outlook
            myType = "Internet"
        Else
            'no outlook and no web mail
            MsgBox "You need one or the other!", vbOKOnly, "Mail Query"
            Exit Sub
        End If
    Me.cboMyCombo = ""
   
End Select
    Me.cboLabel.Caption = myCaption
    Me.cboMyCombo.RowSource = myRecordSource
    Me.cboMyCombo.Requery
   
    If myType = "Outlook" Then
        'send with outlook
        myMail = DLookup("intmailaddress", "tblUsers", "UserID =" & Chr(34) & Environ("username") & Chr(34))
        DoCmd.SendObject , , , "YourName@YourDomain.com", myMail, , "Help me!", , True
        ElseIf myType = "Internet" Then
        'send with web based
        myMail = DLookup("extmailaddress", "tblUsers", "UserID =" & Chr(34) & Environ("username") & Chr(34))
        Call fHandleFile(myMail, WIN_NORMAL)
    End If

Exit Sub
'-----------------------------------------------------
Errtrap:
MsgBox "Encountered an error." & vbLf & "Either:" & vbLf & "1. You are not a registered user," & vbLf & "2. You cancelled the send mail operation, or" & vbLf & "3. Another error has occured", vbOKOnly, "Error"

End Sub
'------------------------------------------------------
Private Sub Form_Load()
Dim myCaption As String
Dim myRecordSource As String

    myCaption = "Do you have an internet connection to this pc?"
    myRecordSource = """Yes""; ""No"""
    myStatus = 1
    Me.cboLabel.Caption = myCaption
    Me.cboMyCombo.RowSource = myRecordSource
    Me.cboMyCombo.Requery
End Sub
'---------------------------------------------------
0
 
LVL 4

Author Comment

by:billcute
ID: 13963992
Dan,
This works very well. Thanks for your assistance.
0
 
LVL 14

Expert Comment

by:bluelizard
ID: 13965533
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
0
 
LVL 4

Author Comment

by:billcute
ID: 13965806
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
0
 
LVL 14

Expert Comment

by:bluelizard
ID: 13965950
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

0
 
LVL 4

Author Comment

by:billcute
ID: 13966770
bluelizard,
Okay, I see your point, hmmm...my fault, not to worry.
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

Question has a verified solution.

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

Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

839 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