How to send SMTP Mail via Port using CDOSYS with Basic Authentication
Here is a sample script to send SMTP mail via Port using CDOSYS with Basic Authentication.
1: 'Sending SMTP Mail by Port 25 Using CDOSYS with Basic Authentication
2: 'Refer the following article for sending mail with out using authentication : https://msdn.microsoft.com/en-us/library/ms992546(EXCHG.65).aspx
3: 'IMP: Please update the TODO: marked line as per the information required earlier than using the script
4:
5: Dim iMsg
6: Dim iConf
7: Dim Flds
8: Dim strHTML
9: Dim strSmartHost
10:
11: Const cdoSendUsingPort = 2
12: Const cdoBasic = 1
13:
14: strSMTPServer = "mail.example.com" 'TODO:
15: username = "user" 'TODO:
16: password = "password" 'TODO:
17:
18:
19: set iMsg = CreateObject("CDO.Message")
20: set iConf = CreateObject("CDO.Configuration")
21:
22: Set Flds = iConf.Fields
23:
24: ' set the CDOSYS configuration fields to use port 25 on the SMTP server
25:
26: With Flds
27: .Item("https://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
28: .Item("https://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTPServer
29: .Item("https://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
30: .Item("https://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
31: .Item("https://schemas.microsoft.com/cdo/configuration/sendusername") = username
32: .Item("https://schemas.microsoft.com/cdo/configuration/sendpassword") = password
33: .Item("https://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
34: .Update
35: End With
36:
37: ' build HTML for message body
38: strHTML = "<HTML>"
39: strHTML = strHTML & "<HEAD>"
40: strHTML = strHTML & "<BODY>"
41: strHTML = strHTML & "<b> This is the test HTML message body</b></br>"
42: strHTML = strHTML & "</BODY>"
43: strHTML = strHTML & "</HTML>"
44:
45: ' apply the settings to the message
46: With iMsg
47: Set .Configuration = iConf
48: .To = "nrnoble@example.com" 'TODO:
49: .From = "nrnoble@example.com" 'TODO:
50: .Subject = "This is a test CDOSYS message (Sent via Port 25) with Basic Authentication"
51: .HTMLBody = strHTML
52: .Send
53: End With
54:
55: ' cleanup of variables
56: Set iMsg = Nothing
57: Set iConf = Nothing
58: Set Flds = Nothing
59:
60:
Please feel free to post your comments for the posted contents or request regarding Microsoft Messaging Development issues. I would like to explore the messaging world further with you.