SendEmailMsgv2023

Sending email using Microsoft 365 account.
Edit 2024-01-02: Adding ability to send from 1 or 2, 2 hosts option, 1 is Mochahost, 2 is Godaddy Plesk account.
FromHost is either 1 or 2 based on where are you sending from.
You need to have a connector in Microsoft 365 account to accept those servers by providing IP in that connector.

Finally, fix the issue with my email system, it was by following instructions from Microsoft https://learn.microsoft.com/en-us/exchange/mail-flow-best-practices/how-to-set-up-a-multifunction-device-or-application-to-send-email-using-microsoft-365-or-office-365?WT.mc_id=365AdminCSH_globalsearch

CodeFunctionName
What is this?

Public

Tested

Original Work
Function SendEmailMsg_2hosts_v2024(EmailTo, EmailFrom, EmailSubject, EmailBody, FromHost)
    ' Admin Settings
    '    Send using my godaddy host, Windows Plesk
    '    Send to outside organization
    '    Added TXT DNS record having ... v=spf1 include:secureserver.net -all
    '   
    Set myMail                = Server.CreateObject("CDO.Message")
    myMail.Subject            = EmailSubject
    myMail.TextBody        = EmailBody
    myMail.To                = EmailTo
    myMail.From                = EmailFrom
    If FromHost = 1 Then ' Sending from Mochahost
        MsgServer            = "domain.mail.protection.outlook.com"
        MsgUserName            = "email@boldcodes.com"
        ' MsgUserPwd        = "???????" looks like it is not needed
       
        myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")                    = MsgServer
        myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername")                    = MsgUserName
        ' myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword")                    = MsgUserPwd
        myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendtls")                        = True
        myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")                        = 2
        myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl")                    = 1
        myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")                = 25 ' 587
        myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")            = 1
        myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout")        = 10
        myMail.Configuration.Fields.Update
        myMail.Send
    ElseIf FromHost = 2 Then ' Sending from Godaddy
        MsgServer                = "relay-hosting.secureserver.net"
        MsgUserName                = "email@boldcodes.com"
        MsgUserPwd                = "[email password]"
       
        myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")                    = MsgServer
        myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername")                    = MsgUserName
        myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword")                    = MsgUserPwd
        myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendtls")                        = False
        myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")                        = 2
        myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl")                    = 0 ' 1
        myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")                = 25 ' 587
        myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")            = 0 ' 1
        myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout")        = 10
        myMail.Configuration.Fields.Update
        myMail.Send
    End If
   
    Set myMail                = Nothing
End Function

EmailTo, EmailFrom, EmailSubject, EmailBody, FromHost

MsgSubject                    = "Its alive!"
MsgBody                    = "Hello, this is ANmar from ANmarSystems trying my emailing system"
MsgTo                            = "emailto@domain.com"
MsgFrom                        = "mail2@domain.com"

SendEmailMsgv2023 MsgTo, MsgFrom, MsgSubject, MsgBody

Views 242

Downloads 74

CodeID
DB ID