Solved I want to be able to send a few emails in access 2016 using gmail but am having challenges

nector

Member
Local time
Today, 23:02
Joined
Jan 21, 2020
Messages
484
Am trying to configure a simple email system in MS Access 2016 so that I can directly send invoices from MS Access 2016 using a form. I have put a button on a form as onclick event, but whenever, I try to send an email I'm getting an error message saying:

"Check your internet", transportation has failed

But internet is working okay.

Code:
Private Sub Send_btn_Click()
'for early binding, enable tools > References > Microsoft CDO for Windows 2000 Library

Dim Newmail As Object
Dim mailConfig As Object
Dim fields As Variant
Dim msConfigURL As String

On Error GoTo Err1:
'late binding
Set Newmail = CreateObject("CDO.Message")
Set mailConfig = CreateObject("CDO.configuration")

mailConfig.Load -1
Set fields = mailConfig.fields

    With Newmail
        .Sender = "nector@gmail.com"
        .From = "Nector Prime Accounting Solutions"
        .To = Me.SendTo
        .CC = Me.CC
        .Subject = Me.Subject
        .TextBody = Me.Message
        .AddAttachment Me.Attachment
        
        End With
        
msConfigURL = "http://schemas.microsoft.com/cdo/configuration"
    With fields
        .Item(msConfigURL & "/sendusing") = cdoSendUsingPort
        .Item(msConfigURL & "/smtpusessl") = True 'enable the SSL authentication
        .Item(msConfigURL & "/smtpauthenticate") = cdoBasic
        .Item(msConfigURL & "/smtpserver") = "smtp.gmail.com"
        .Item(msConfigURL & "/smtpserverport") = 587
        .Item(msConfigURL & "/BodyFormat") = 2
        .Item(msConfigURL & "/sendusername") = "nector@gmail.com" 'input your gmail here
        .Item(msConfigURL & "/sendpassword") = "xxxxxxxxxxxx"
        .Item(msConfigURL & "/smtpconnectiontimeout") = 10
        .Update 'update the configuration fields
        
    End With
    
    Newmail.Configuration = mailConfig
    Newmail.Send
    MsgBox "Your email has been sent.", vbInformation, "Sent"
    Me.Status = "Sent"
    
Exit_Err1:
'release object memory
Set Newmail = Nothing
Set mailConfig = Nothing
End
    
Err1:
    Select Case Err.Number
    Case -2147220973 'due to internet connection
    MsgBox "check your internet connection." & vbNewLine & Err.Number & ": " & Err.Description, vbExclamation, "Internal Audit Manager"
    
    Case -2147220975 ' due to incorrect credentials
    MsgBox "Incorrect Credentials." & vbNewLine & Err.Number & ": " & Err.Description, vbExclamation, "Internal Audit Manager"
    
    Case 13 'missing information
    MsgBox "Please fill up the required fiels." & vbNewLine & Err.Number & ": " & Err.Description, vbExclamation, "Internal Audit Manager"
    
    Case -2146697203 'Invalid link for attachment
    MsgBox "Invalid Link for attachment"
        
        Case Else
        MsgBox "Error encountered while sending and email.", vbCritical, "Unsend"
        
        End Select
        Resume Exit_Err1
End Sub

Email Error.png
 
Is this with single or dual factor authentication to log in to the GMail account?
And to verify, have you been able to get a return from pinging the server prior to testing?
 
maybe there is answer here specially the port number for SSL and the timeout value.

 
Since you are using CDO, technically you are not using gmail from your machine, you are using "raw" SMTP aimed at a mail server.

1. Do you have a site-declared local SMTP Server set up? It LOOKS like you are trying to send using THE gmail server as your target.
2. What client does your laptop or desktop machine use? Can you send mail manually through your mail client from that machine with that particular SMTP server URL that you used in the code?
3. Do you have a restrictive network setup in that environment? This last question is because some networks disallow STMP or other types of automated message transmission if it didn't originate from an "expected" client. In my case, anything that wasn't OUTLOOK (our mail client) was not allowed to send to the SMTP server, which was on the other side of a firewall. I had to get my IT group to give me an "Allow" for SMTP from MSACCESS.EXE - and yes, it could see that level of detail to recognize that fine point of not only WHO was sending anything but HOW they were sending it.
 
still nothing is working out
If you haven’t changed anything, I’m not surprised. If you have changed something do have the courtesy of showing your revised code, ideally identifying what you have changed
 
Okay many thanks to all contributors no answer is wrong they are all valuable and I appreciate you all. Finally, Mark above hinted something about dual authentication, and from there I have used the Gmail application password, and it has sorted out the problem.
 

Users who are viewing this thread

Back
Top Bottom