CDO error '8004020f' External Mail; Windows Server 2012 R2

I recently migrated from a Windows Server 2008 R2 running web services to a Windows 2012 R2 server running the same.  I performed the Web Deploy tools and migrated all of the IIS info to the WS2012R2.  The only item that I cannot get to work now is this simple CDO mail going to external addresses, but this function still works on the WS2008R2.

I have read many tech help articles but none of the solutions apply to my situation.   i cannot find what I have set on the 2008 server which allows this, but is blocked on the 2012 server.

Set myMail=CreateObject("CDO.Message")
myMail.Subject="Activity Counts"

myMail.TextBody = Session("TextBody")

myMail.Configuration.Fields.Item _
'Name or IP of remote SMTP server
myMail.Configuration.Fields.Item _
'Server port
myMail.Configuration.Fields.Item _
set myMail=nothing

Open in new window

I have also tried to use the following with no luck:

Const cdoAnonymous = 0       ' Do not authenticate
Const cdoBasic = 1           ' Basic (clear-text) authentication
Const cdoNTLM = 2            ' NTLM
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Simple plain text CDO example"
objMessage.From = ""
objMessage.To = ""
objMessage.TextBody = Session("TextBody")
' Configure the send to use another server
objMessage.Configuration.Fields.Item _
("") = 2
' Set the name or IP of the remote SMTP Server
objMessage.Configuration.Fields.Item _
("") = ""
' Set the type of authentication to use, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.Fields.Item _
("") = cdoBasic
' Set your UserID on the SMTP server (some SMTP servers require your e-mail address)
objMessage.Configuration.Fields.Item _
("") = "administrator"
' Set your password on the SMTP server
objMessage.Configuration.Fields.Item _
("") = "pwd"
' Set the server port (usually 25)
objMessage.Configuration.Fields.Item _
("") = 25
' Set if the connection should use SSL (False or True)
objMessage.Configuration.Fields.Item _
("") = False
' Set the connection timeout in seconds
' (the maximum time CDO will try to establish a connection to the SMTP server)
objMessage.Configuration.Fields.Item _
("") = 60
' Save the new configuration settings

Open in new window

The error always points to the objMessage.Send line of code.  If I change the to an internal user, all is good.  Does anyone have any other links or ideas?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
You probably need to authenticate.  You have it set to do not authenticate.
montepkgAuthor Commented:
Thanks for responding!  Are you referring to the code or the server in IIS?  The first portion of code works on the 2008 server and i do not have the authenticate set there.  Is this a 2012 R2 issue?
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
The 2nd code snippet does look like you are authenticating.  What is the actual error code you are getting.

Are you sure the username is not the full email account like rather than "administrator"

Is the email account set to allow remote authentication?

Is port 25 being blocked and do you need to use an alternate port for that account?

Did you try sendusing pick up instead of port?

These are all wild guesses though.  Your exact error will help.
Dan McFaddenSystems EngineerCommented:
I would verify that the IP address where the script is running is allow to relay externally.  You will need to check the SMTP config.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
montepkgAuthor Commented:
Yes,  I neglected to look at the Exchange Server > Server Config > Hub Transport > Relay

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft IIS Web Server

From novice to tech pro — start learning today.