Hi all,
I had some SMTP emails that were working just fine. But now my organization requires that we use authentication to send out to outside domain emails.
My working code is as seen below:
Code:
Sub SendEmail(sTo As String, sSubject As String, Optional sBody As String, Optional sAttachment As String, Optional sBCC As String)On Error GoTo SendEmail_Err
Start:
Set objmessage = CreateObject("CDO.Message")
With objmessage
.From = "LV_Reports@orgdomain.org"
.To = sTo
.BCC = sBCC
.Subject = sSubject
.HTMLBody = sBody
If sAttachment <> "" Then
.AddAttachment sAttachment
End If
.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.orgserver.org"
.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Configuration.Fields.Update
.Send
End With
Exit Sub
SendEmail_Err:
'MsgBox Err.Number & " is the errror code for this event. " & Err.Description
If Err.Number = -2147024864 Then
Shell "TASKKILL /F /IM EXCEL.exe"
GoTo Start
'LogError Err.Number, Err.Description & " - " & sAttachment, "SendEmail", , False
ElseIf Err.Number = -2147220973 Or Err.Number = -2147220975 Then
GoTo Start
Else
LogError Err.Number, Err.Description & " - " & sAttachment, "SendEmail", , False
End If
Debug.Print
End Sub
I did some research and found that something along the lines of this code needs to be added. But i can't get it to work.
Code:
.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "myusername"
.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "mypassword"
.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
Any ideas how i'm supposed to authenticate via SMTP?