How to send a Email Using SMTP Sevre Authentication

I would like to send a email message using CDOSYS, which is used when the computer does not have a direct connection to the local server. The code below will not work because I keep getting a error message stating. "Property Items is read only" It located on this section of Code. I have attached the complete Code in the Code section

Config.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        Config.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.charter.net"
        Config.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "MyEmail@MyDomain.com"
        Config.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "MyPa$$word"
        Config.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1

Dim MyMessage As New CDO.Message()
        Dim Config As New CDO.Configuration()
 
        ' This part is required if your mail server requires authentication
        Config.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        Config.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.charter.net"
        Config.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "MyEmail@MyDomain.com"
        Config.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "MyPa$$word"
        Config.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
 
        Config.Fields.Update()
        MyMessage.Configuration = Config
 
        'Create The message.
 
        MyMessage.To = ""
        MyMessage.From = ""
 
        MyMessage.Subject = "A New Email Message"
        MyMessage.TextBody = "I hope you get this email! Ill talk to you later!"
 
 
        Try
 
            'Send The CDOSYS
            MyMessage.Send()
 
        Catch Ex As Exception
 
        End Try

Open in new window

CDOSystem.txt
daruffinAsked:
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.

hieloCommented:
Try this:
Dim MyMessage As New CDO.Message()
 
        ' This part is required if your mail server requires authentication
        MyMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        MyMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.charter.net"
        MyMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "MyEmail@MyDomain.com"
        MyMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "MyPa$$word"
        MyMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
 
        MyMessage.Configuration.Fields.Update()
 
 
        'Create The message.
 
        MyMessage.To = ""
        MyMessage.From = ""
 
        MyMessage.Subject = "A New Email Message"
        MyMessage.TextBody = "I hope you get this email! I.ll talk to you later!"
 
 
        Try
 
            'Send The CDOSYS
            MyMessage.Send()
 
        Catch Ex As Exception
 
        End Try

Open in new window

0
daruffinAuthor Commented:
I'm still getting a blue line under the code stating Property 'Item is readonly
0
hieloCommented:
How about this:
Dim MyMessage As CDO.Message
MyMessage = New CDO.Message()
 
        ' This part is required if your mail server requires authentication
        MyMessage.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        MyMessage.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.charter.net"
        MyMessage.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "MyEmail@MyDomain.com"
        MyMessage.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "MyPa$$word"
        MyMessage.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
 
        MyMessage.Configuration.Fields.Update()
 
 
        'Create The message.
 
        MyMessage.To = ""
        MyMessage.From = ""
 
        MyMessage.Subject = "A New Email Message"
        MyMessage.TextBody = "I hope you get this email! I.ll talk to you later!"
 
 
        Try
 
            'Send The CDOSYS
            MyMessage.Send()
 
        Catch Ex As Exception
 
        End Try
Set MyMessage = Nothing

Open in new window

0

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
daruffinAuthor Commented:
This worked just fine now. Thanks so much for your help
0
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
Email Servers

From novice to tech pro — start learning today.