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.
"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