Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919

    Sending emails from Access VBA

    From one of Paul's old posts https://www.devhut.net/vba-outlook-automation/, Daniel Pineault offers a clean method of sending emails via Outlook. The problem, or at least where I'm currently bumping my head, is that gmail isn't allowing Outlook to access its servers. I thought I could circumvent that issue with the gmail 2-step verification available at Google, but don't see it at Google for Outlook.



    Any ideas for an alternative? I only need to periodically "Send" emails with attachments.

    EDIT:
    I found this, but imposing this kind of scenario upon a user doesn't seem like a reasonable request.
    https://blog.gsmart.in/2-step-verifi...gmail-outlook/

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    5,009
    You now use the authentication password that google gives you, when you select that option. Do not lose it either.

    Then there is outlook.com?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,992
    As I think I've mentioned to you before you can send email from Access without involving an external app such as Outlook
    See my example app: CDO EMail Tester (isladogs.co.uk)
    CDO does still work with GMail by using the set app password feature mentioned above
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  4. #4
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Thanks Colin, I'll chime back in a couple of hours.


    EDIT: I owe you an apology Colin. You "taught" me some time ago about CDO and I completely forgot. I even ran your test module at that time and recall how simple it was. My only excuse is that this fuzzy old brain of mine continues to be troublesome, as evidenced by this OP.

  5. #5
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    CDO does still work with GMail by using the set app password feature mentioned above
    I can't find the option that Welshgasman mentions.

  6. #6
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,992
    See the help file that is supplied with my example app. It includes info on how to apply an app password. Its not done within Access itself.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  7. #7
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    Thanks Colin, the biggest help is found here: https://support.google.com/accounts/answer/185833

  8. #8
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,992
    Correct. That tells you all you need to do to keep CDO working with GMail's new security measures
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  9. #9
    TOPSie is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Mar 2021
    Posts
    114

    Taking Gmail a few steps forward.

    Thanks to you and Philipp I can now successfully send emails from Access using a Gmail account.

    But there a couple of tweaks I would like to make.

    My (ficticious) Gmail account is Smith.John@gmai.com. I have gone into Gmail directly and changed the "Send Mail as" value to John Smith and I have changed the Reply to address to Joe.Bloggs@gmail.com

    If I use Gmail directly to send an email then it arrives from "John Smith" and if you reply it sends it to Joe.Bloggs

    However if I use the CDO code these two new values are ignored and the from and reply are both set to Smith.John@gmail.com

    Are there some CDO setting I can update to give the Gmail from/to effect?

    Thanks

    Geoff

    with apologies to all John Smith's and Joe Bloggs everywhere

  10. #10
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,992
    Hi Geoff (assuming that's not fictitious as well!)

    Its easy to change the From address to something else which will have the effect you want

    Click image for larger version. 

Name:	Capture.PNG 
Views:	18 
Size:	8.2 KB 
ID:	51780

    This was sent from my CDO Email Tester app.
    To do this I entered real email credentials for an account then just changed the '"Your Email address" (From) value to something fictitious - in this case no-reply@mickey-mouse.com

    I see no reason why that wouldn't work with GMail accounts (untested)
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  11. #11
    TOPSie is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Mar 2021
    Posts
    114
    Colin,

    Thanks for the quick reply.
    I did try your suggestion (before I posted) and unfortunately the only thing in the recieved email is the Username field - the "Your email address" does not appear in the received From field. If the receiving email is Outlook the Outlook Propeties show the username as both Display Name and E-mail address

    And yes it is

    Geoff 0(but I have several aliases :-)

  12. #12
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,992
    Hi again
    Just tested and you are right. Google no longer allows you to 'spoof' a send address.
    Overall that's a good thing but it doesn't help you at all
    Sorry but I don't have a solution for you in connection with GMail
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  13. #13
    TOPSie is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Mar 2021
    Posts
    114
    Colin,

    Ho hum. I suppose someone somewhere might know of a Google API to send emails, rather than CDO, but I have never delved that deep.

    I will have a browse and let you know if anything turns up

    Geoff

  14. #14
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,992
    Actually I do have a solution for you! With hindsight, it was blindingly obvious as a workaround

    Send the email using CDO from a non GMail account but set the From address as the GMail account you want to appear.
    That does work (tested!) and users will reply to that GMail address
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  15. #15
    TOPSie is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Mar 2021
    Posts
    114
    Quote Originally Posted by isladogs View Post
    Actually I do have a solution for you! With hindsight, it was blindingly obvious as a workaround

    Send the email using CDO from a non GMail account but set the From address as the GMail account you want to appear.
    That does work (tested!) and users will reply to that GMail address
    Personally I only have one non-Gmail account, with an obscure outfit called NetNerd. This account exhibits the same behaviour - the "Your email address" & "username" must be the same.

    So I tried the clients Office 365 account smtp.office365.com. Port 25 and 587 fail immediately x80040211 and x80040213 resoectively. Port 465 fails x80040213 but only after the timeout period

    If I could get this to work with 365 it would be the ideal solution as the address problem goes away as it would be the "right" address from the start

    Geoff

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. sending emails using VBA
    By StuartR in forum Access
    Replies: 4
    Last Post: 02-19-2018, 04:56 AM
  2. Sending Outlook Emails from form in Access 2007
    By IncidentalProgrammer in forum Programming
    Replies: 4
    Last Post: 01-09-2015, 11:06 AM
  3. Sending Emails from Access via Outlook
    By Terry Lawson in forum Programming
    Replies: 3
    Last Post: 11-14-2014, 10:03 AM
  4. Generating and sending emails through Access
    By crowegreg in forum Programming
    Replies: 9
    Last Post: 06-10-2013, 08:35 AM
  5. Replies: 1
    Last Post: 11-14-2012, 01:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums