I'm having issues with sending emails out of MS Access using CDO SMTP. This has been working without issue for a number of years but now over recent times have been getting -2147220973 The transport failed to connect to the server error on a regular basis - nor every email, maybe 30%. I believe this is due to changes made by Microsoft in phasing out TLS 1.0, 1.1, although from what I've read the code I (and a lot of others are using) doesn't actually take that into account. But anyway, i can't find any other options for sending out emails out of MS Access that doesn't use CDO and/or that will consistently work. Below is the code, similar to what a lot of others are using. Have also tried ports 587 and 465 and with and without the SendTLS option:
Function Mailer(SendTo As String, SendFrom As String, SendBCC As String, Sender As String, Subject As String, Body As String, IsHTML As Boolean, Attach As Boolean, AttPath As String, ReqRec As Boolean, FName As String)
Body = Body & Chr(13) & Chr(10) & Chr(13) & Chr(10) & Chr(13) & Chr(10) & "THIS MAILBOX IS NOT MONITORED. PLEASE DO NOT REPLY!"
Dim iMsg As New CDO.Message
Dim iBp As CDO.IBodyPart
Dim Configuration
Set Configuration = CreateObject("CDO.Configuration")
Configuration.Load -1 ' CDO Source Defaults
Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = DLookup("[SMTPsendusing]", "tblCompanyInfo") '2
Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = DLookup("[SMTPServer]", "tblCompanyInfo") ' "smtp.office365.com"
Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = DLookup("[SMTPServerPort]", "tblCompanyInfo") '25
Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = DLookup("[SMTPauthenticate]", "tblCompanyInfo") '1
Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = DLookup("[SMTPsendusername]", "tblCompanyInfo") '"email@doamin.co.nz"
Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = DLookup("[SMTPsendpassword]", "tblCompanyInfo") '"*********"
Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = DLookup("[SMTPuseSSL]", "tblCompanyInfo") 'True
Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendtls") = DLookup("[SMTPSendTLS]", "tblCompanyInfo") 'True
Configuration.Fields.Update
With iMsg
Set .Configuration = Configuration
.To = SendTo
.From = SendFrom
.BCC = SendBCC
.Sender = Sender
.Subject = Subject
If IsHTML = True Then
.HTMLBody = Body
Else
.TextBody = Body
End If
If ReqRec = True Then
.MDNRequested = True
End If
If Attach = True Then
Set iBp = .AddAttachment(AttPath & FName)
'iBp.ContentMediaType = "text/html"
iBp.ContentMediaType = "text"
End If
.Send
DoEvents
End With
End Function
Any assistance appreciated. Thanks