Solved Send Mail Direct Through Gmail (1 Viewer)

Jayessh

Registered User.
Local time
Today, 17:26
Joined
Dec 30, 2019
Messages
36
I need to set a button on form which

Create Excel File using Query Output and Mail it Direct using Gmail...

I mean I don't need Outlook in between, Coz Sometime When Outlook was not Configured after System Format... The Process is not Worked properly till Outlook configured

Do anyone have solution ?
 

Jayessh

Registered User.
Local time
Today, 17:26
Joined
Dec 30, 2019
Messages
36
Hi. You could try using CDO.

Giving This Error
1605187829892.png
 

shadow9449

Registered User.
Local time
Today, 07:56
Joined
Mar 5, 2004
Messages
1,037
Important: when did you create the Gmail account?

Google is discontinuing Less Secure Apps (possibly as soon as February) in favour of OAuth. Accounts created before this past July (I think) can still use LSA; accounts created after July cannot. So, if you created your account after July your option are to either use OAuth (I am not aware of anyone who's done that successfully from Access) or you can use 2-step verification and an APP Password, described here:

 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 11:56
Joined
Jul 9, 2003
Messages
16,245
I researched sending email with Gmail a while back and I blogged about it on my website here:-


I do recall that since my blog, Google have changed the security measures, which are discussed on some of the threads linked to from my blog, but it is quite a while back and may well be out of date.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 04:56
Joined
Oct 29, 2018
Messages
21,358
Hi. The OP in this other thread was able to get CDO working with GMail. Looking at their code and the screenshot you posted earlier, I noticed your using a different Port number and no Authentication.

Could you try using Port 465 and select Basic Authentication and try the Demo again? Thanks.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:56
Joined
May 7, 2009
Messages
19,175
a simple working version, copy in a new Module:
Code:
Private Const cdoSendUsingPort = 2
Private Const cdoBasic = 1

Public Sub SendSimpleCDOMailWithAuthenticationAndEncryption()
    
    Dim mail    As Object           ' CDO.MESSAGE
    Dim config  As Object           ' CDO.Configuration
    
    Set mail = CreateObject("CDO.Message")
    Set config = CreateObject("CDO.Configuration")
    
    config.fields(cdoSendUsingMethod).Value = cdoSendUsingPort
    config.fields(cdoSMTPServer).Value = "smtp.gmail.com"
  
    config.fields(cdoSMTPServerPort).Value = 465  ' implicit SSL - Does not work with Explicit SSL (StartTLS) usually on Port 587
    config.fields(cdoSMTPUseSSL).Value = "true"
    
    config.fields(cdoSMTPAuthenticate).Value = cdoBasic
    config.fields(cdoSendUserName).Value = "your@gmail.com"
    config.fields(cdoSendPassword).Value = "yourGmailpassword"

    config.fields.Update
    
    Set mail.Configuration = config
    
    With mail
        .To = "Receiver_Email_Address"
        .From = "your@gmail.com"
        .Subject = "First email with CDO"
        .Textbody = "This is the body of the first plain text email with CDO."
        
        '.AddAttachment "C:\path\to\a\file.dat"
        
        .Send
    End With
    
    Set config = Nothing
    Set mail = Nothing
    
End Sub
 

Jayessh

Registered User.
Local time
Today, 17:26
Joined
Dec 30, 2019
Messages
36
Hi. The OP in this other thread was able to get CDO working with GMail. Looking at their code and the screenshot you posted earlier, I noticed your using a different Port number and no Authentication.

Could you try using Port 465 and select Basic Authentication and try the Demo again? Thanks.
And...... it Worked......!!!

Thank You Very Much...

All I need to do is configure this form with my Database and set auto attachment to it...
 

theDBguy

I’m here to help
Staff member
Local time
Today, 04:56
Joined
Oct 29, 2018
Messages
21,358
And...... it Worked......!!!

Thank You Very Much...

All I need to do is configure this form with my Database and set auto attachment to it...
Right. Sorry I didn't include attachments to the demo. Let us know if you run into any problems.
 

isladogs

MVP / VIP
Local time
Today, 11:56
Joined
Jan 14, 2017
Messages
18,186
@Jayessh
My CDO EMail Tester app (see link in posts #6 & #9 was created in Access 2010. Looks like you are using A2007.
Let me know if you would like a version that works in A2007
 

Jayessh

Registered User.
Local time
Today, 17:26
Joined
Dec 30, 2019
Messages
36
@Jayessh
My CDO EMail Tester app (see link in posts #6 & #9 was created in Access 2010. Looks like you are using A2007.
Let me know if you would like a version that works in A2007
Dear @isladogs

Actually Adding Attachment is also worked fine.. Just I need to do is User should prompted by system to select the file... Currently The Attachment is taken by Typing Path in "txtAtmnt" Box

I'm using this code:

Call .AddAttachment(Me.txtAtmnt)


Form is this


1605521121945.png
 
Last edited:

isladogs

MVP / VIP
Local time
Today, 11:56
Joined
Jan 14, 2017
Messages
18,186
I've converted it to A2003 MDB format which should work fine in A2007. Hope that helps
 

Attachments

  • CDO EMail Tester v1908 - MDB Version.zip
    385.5 KB · Views: 148

Jayessh

Registered User.
Local time
Today, 17:26
Joined
Dec 30, 2019
Messages
36
Right. Sorry I didn't include attachments to the demo. Let us know if you run into any problems.

One of My Button is ruining this macro to export an Excel File
What I need is... is it Possible to Attach This Generated file directly or at least Fill The Field of EMail Sender where user should enter FilePath... So user should not prompted for to enter filepath as it is quite tricky and need more accuracy (I'm attaching here two Screen Shots 1) Macro and 2) Email Screen who is taking filepath
1605596590730.png



1605596870769.png
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:56
Joined
May 7, 2009
Messages
19,175
you can use the Load event of your form to fill the Attachment textbox:

private sub form_load()
me!txtAttachment = "E:\E Drive\Jaxpro\Excel4Mail\XL4Salary.xlsx"
end sub

or you can use the Default property of the textbox and directly write the path+filename of the excel file.
 

Users who are viewing this thread

Top Bottom