Sending Email from Access Database

0

I'm trying to send email from Access.

I verified the credentials are correct, SMTP settings are enabled on Office 365. I get this error.

The message could not be sent to the SMTP server. The transport error code was 0x80040217. The server response was not available.

If I change the port to "587" or "465", it shows the error

"Run-time error -2147220973 (80040213). The transport failed to connect to the server."

If there is any alternative solution, 3rd party library, I'm open to all options.

I tried (https://youtu.be/mWf-FExqGr8). It works but it's not allowing me to add custom account other than configured with my Outlook.

Option Compare Database
Option Explicit
    
Private Const cdoSendUsingPort = 2
Private Const cdoBasic = 1
Private Const cdoNTLM = 2
    
' The docmentation of all these settings is available at
' https://msdn.microsoft.com/en-us/library/ms872853.aspx
    
Private Const cdoSendUsingMethod = "http://schemas.microsoft.com/cdo/configuration/sendusing"
Private Const cdoSMTPServer = "http://schemas.microsoft.com/cdo/configuration/smtpserver"
Private Const cdoSMTPServerPort = "http://schemas.microsoft.com/cdo/configuration/smtpserverport"
Private Const cdoSMTPUseSSL = "http://schemas.microsoft.com/cdo/configuration/smtpusessl"
Private Const cdoSMTPAuthenticate = "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"
Private Const cdoSendUserName = "http://schemas.microsoft.com/cdo/configuration/sendusername"
Private Const cdoSendPassword = "http://schemas.microsoft.com/cdo/configuration/sendpassword"
    
Public Sub SendSimpleCDOMailWithBasicAuthentication()
    
    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.office365.com"
    config.Fields(cdoSMTPServerPort).Value = 25
        
    config.Fields(cdoSMTPAuthenticate).Value = cdoBasic
    config.Fields(cdoSendUserName).Value = "from@test.onmicrosoft.com"
    config.Fields(cdoSendPassword).Value = "@password"
    
    config.Fields(cdoSMTPUseSSL).Value = "true"
    
    config.Fields.Update
        
    Set mail.Configuration = config
        
    With mail
        .To = "To@gmail.com"
        .From = "from@test.onmicrosoft.com"
        .Subject = "First email with CDO"
        .TextBody = "This is the body of the first plain text email with CDO."
            
        .AddAttachment "D:\my daily work.txt"
        
        .Send
    End With
        
    Set config = Nothing
    Set mail = Nothing
        
End Sub

enter image description here

enter image description here

vba
ms-access
asked on Stack Overflow Mar 10, 2021 by Arwa Technologies • edited Mar 21, 2021 by Community

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0