Function to send email fails.

Hi Experts,

We have the following function that used to work for years, now suddenly its starting to cause problems.

Public Sub SendEmail(Optional sTo As String = "", Optional sFrom As String = "", Optional sSubject As String = "", Optional sBody As String = "")
    Dim imsg As Object
    Dim iconf As Object
    Dim flds As Object
    Dim schema As String

    Set imsg = CreateObject("CDO.Message")
    Set iconf = CreateObject("CDO.Configuration")
    Set flds = iconf.Fields

    ' send one copy with SMTP server (with autentication)
    schema = ""
    flds.Item(schema & "sendusing") = cdoSendUsingPort
    flds.Item(schema & "smtpserver") = ""
    flds.Item(schema & "smtpserverport") = 3535
    flds.Item(schema & "smtpauthenticate") = cdoBasic

    flds.Item(schema & "sendusername") = ""
    flds.Item(schema & "sendpassword") = "MyPWD"
    flds.Item(schema & "smtpusessl") = False

    With imsg
        .To = sTo
        .From = sFrom
        .Subject = sSubject
        .HTMLBody = sBody
       '.Sender = "Sender"
        '.Organization = "My Company"
        '.ReplyTo = ""
        Set .Configuration = iconf
    End With

    Set iconf = Nothing
    Set imsg = Nothing
    Set flds = Nothing
End Sub

Open in new window

See attached error message.
Who is Participating?
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.

The error message seems like the SMTP communication was blocked because of:

1.  Local firewall is blocking it
2.  Relaying is disabled.  Can you verify with the email administrator that relaying is allowed?  
3.  Email server firewall is blocking it
John TsioumprisSoftware & Systems EngineerCommented:
Have you changed something in the email configuration ..e.g version of Exchange server..Exchange 2016 doen't work with CDO.
EDIT..i see you use GoDaddy email functionality...maybe you should drop them a ticket to see is something needs to be done.
bfuchsAuthor Commented:
Hi Experts,
Have you changed something in the email configuration ..e.g version of Exchange server
Yeah, guess this was working till now while our GoDaddy account was still active...
Wondering what needs to be changed in order to work.
Exchange 2016 doen't work with CDO.
I see from the following it should work.

BTW, I'm open for other suggestions, not bounded to CDO (as long as they work and easy to apply/maintain..).

Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Since you mentioned Go Daddy, are you using hosted Exchange or on-site?
bfuchsAuthor Commented:
Since you mentioned Go Daddy
Oh forgot to mention..We changed for Office 365.
If you changed to Office 365 then it is probably because email relaying is not configured.  Please have a look at these articles:

It's best to call Office 365 support and they should help you with this.
bfuchsAuthor Commented:
I changed for the following
    flds.Item(schema & "smtpserver") = ""
    flds.Item(schema & "smtpserverport") = 25
   ' flds.Item(schema & "smtpauthenticate") = 0

Open in new window

Then we got the attached.
Went online to enlist the IP and it worked.
but after testing 2 times I'm getting the attached msg again..
What are my options?

IMHO, the message strictly refers to "banned sending IP" so it seems as the Office 365 is blocking it because it's suspicious of your script trying to flood the system with emails (spam).

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
bfuchsAuthor Commented:
Thank you my experts!
You're welcome and glad to help.  Cheers!
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
System Programming

From novice to tech pro — start learning today.