MS Access Hints, Tips & Videos

This is the stuff they don't tell you in books...

Sending Google Mail (Gmail) from MS Access, VBA, Excel, Word...

Escape From Outlook
Microsoft tightly combine their applications together however sometimes it’s nice to escape from Microsoft Products and use others.  Here I demonstrate how you can use Google Mail to send out an e-mail from an Internet connected PC, and you can also do this covertly!

 This Example is From:

Windows® XP Under the Hood, Pg. 266 Chapter 6 Messaging and Faxing ObjectsExtract
 This basic example sends a simple, no-frills text message every time the script is run: Example File: script0603.vbs As you can see, the original file was a VBScript file; I have converted this to VBA.

Google e-mail Account
I have also set up a Gmail account to send the emails through.  You are welcome to use this account for testing, however I suggest you set up your own Gmail account and change the hard coded information where necessary if you intend using this code for your own purposes.


Gmail From MS Access (the Video)


Text from the above Video

This video is of a demo MS Access database which shows you how to send an e-mail from Google mail using
VBA.  Press the “Send a Test Email” button and wait and then you get this message saying that the message sent is "True". It doesn't necessarily mean the message has been sent, it just means the code operated successfully. It is not necessary to have that confirmation message appear, this can be hidden, hence you have the ability to send email from your application covertly!


Thank You

BTW there should be a Demo DB linked to from this Video.

 

I was not happy with the original file, so I have replaced it.  If you want the original file then it is available , you will find it at the bottom of my next post in this thread.  

 

Use this Updated Version HERE: UpdatedGoogleMail.mdb

 

Text Version of Code (VBA) for use in older versions of MS Access and other Microsoft Products like MS Excel, MS Word, etc... : GoogleMailFromMS_Access_VBA_CODE.txt

Views: 2697

Comment by TØny Hine on February 16, 2011 at 14:42

Update:

The first example will no longer work --- This second example will work: UpdatedGoogleMail.mdb

My apologies but I got cold feet!  I set-up the 1st example to work through a temporary Gmail account, I realized that the password for the Gmail account was hard coded in the code of the 1st example, I wasn’t too worried about this initially, thinking the code would only be used by sensible MS Access database programmers’, however I became uncomfortable with the thought that there was a very small chance that someone could... let’s say “get up to mischief” with this account, if this happened then I could possibly get blacklisted by Google.

I realise there’s very little chance of this happening, however I am not prepared to take even this small risk. I have changed the password on the linked Google account. Therefore the 1st example will no longer work.

Please use the second example posted here. You will need your own Gmail account, just paste in the "send to" e-mail address, your Google e-mail address and your Google email account password in the boxes provided and it should work.

 

The original database with the hard coded e-mail address and password may be of interest, you can still download it from the link below:

The original example database available here: GoogleMail.mdb (Superseded)

Comment by Thor Gibbons on February 16, 2011 at 16:55
Thank you so much!  I have been looking for something like this for awhile now.  You are the BEST!  It works beautifully.
Comment by Alan Sidman on February 19, 2011 at 23:12

Tony;

Very cool.  If I wanted to take it to the next level and add an attachment to the Build a Message section of the code.  Under oMsg, what code would I add to have it grab a report or query and email it as an attachment.

Alan

Comment by TØny Hine on February 20, 2011 at 1:16

If I wanted to add an attachment:

Add a line after ".textBody" and before "End With" like so:


.textBody = "From Keyed in Email Address"
.AddAttachment "H:\ADrive\YourFileName.txt"
End With

Comment by louis petit on February 23, 2011 at 23:17
This is exactly what I am looking for but my company is using an old version of access :(
Comment by TØny Hine on February 23, 2011 at 23:38

This is exactly what I am looking for but my company is using an old version of access :(

 

It should work with any version of MS Access..

Comment by louis petit on February 24, 2011 at 0:28
Saying googlemail.mbd is unrecognized format, made with newer version of access. We are still using access 2000.  Is just the code anywhere?
Comment by TØny Hine on February 24, 2011 at 10:34

We are still using access 2000 

Ah, now I understand your problem; here is the code:

 

http://api.ning.com/files/PbzRfJvvRQ5AXSrHwyMCRk4pt6TAVOsP4GXXWmXSH...

Comment by Nilsonrdg on July 15, 2011 at 21:15
I copied the code just to test, but it seems there's some risk puting the gmail password in the code (YourGmailPasswordHere).

Even compiling the program,  the programer will need to do something to protect the password?
Comment by TØny Hine on July 15, 2011 at 21:22
Use a separate account just for the purpose of sending these emails

Add a Comment

You need to be a member of MS Access Hints, Tips & Videos to add comments!

Join MS Access Hints, Tips & Videos

Badge

Loading…

Members

© 2015   Created by TØny Hine.   Powered by

Badges  |  Report an Issue  |  Terms of Service