So I am trying to send an automated message from an Excel VBA backend. I'm very competent in my VBA skills and have used the method below with great success in the past. I am having issues using this method in my new environment and I know it has something to do with the configuration of the Exchange server, the issue is that the guy who manages the exchange server nor I are Exchange experts.
Public Function SendEmail(
txtTo As String,
txtSubject As String,
txtBody As String,
Optional txtSender As String = vbNullString,
Optional txtCC As String = vbNullString,
Optional txtBCC As String = vbNullString)
Dim objMsg As Object, objconfig As Object, objFields As Object
Set objMsg = CreateObject("CDO.Message")
Set objconfig = CreateObject("CDO.Configuration")
Set objFields = objconfig.fields
'Set the email configuration
With objFields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "SMTP"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Update
End With
'Apply the various fields to the email object
With objMsg
.Configuration = objconfig
.From = txtSender
.Subject = txtSubject
.To = txtTo
.Cc = txtCC
.Bcc = txtBCC
.TextBody = txtBody
.Send
End With
SendEmail = IIf(Err.Number = 0, True, False)
'clean up
Set objMsg = Nothing
Set objconfig = Nothing
Set objFields = Nothing
End Function
I am attempting to send to a distribution group which requires authentication. We've figured out how to remove that "feature" to send an email but this is not ideal. I've tried using basic/clear trust (1) for the authentication method, supplied my username and password to the required fields in the configuration object and still no dice. When I send an email from Outlook I have no issues sending to an email that requires authentication, but when using CDO Exchange won't allow me to authenticate. It also never resolves the sender address, not sure if that is related or not but for the sake of full disclosure there it is. I know that the Exchange/SMTP server is configured to allow for anonymous sending, but that seems to be the only option that CDO will use.
I'm at my wits end. Any Exchange gurus out there that might be able to offer some suggestions?
Thanks, Chad