Link to home
Start Free TrialLog in
Avatar of Mike Schmidt
Mike Schmidt

asked on

VB.net "Could not access 'CDO.Message' object." only receive error when sending to outside domain, works with internal email address

I have a piece of code shown below which sends emails via code using VB.net VS 2003, using Windows 7 PC, Outlook 2007, and Microsoft Exchange Server 2016 Standard - license, Barracuda Essentials - Advanced Email Security Account anti-spam. I used this code for years no issues although the environment changed. I'm using it for a new company, they have newer version of Exchange and newer OS windows servers running. Although its essentially the same, windows 7, Outlook 2007, and VS 2003 all same. Barracuda is different, believe previous company was using a Google anti-spam email product. The code is below. Its a setting issue (i believe) that's not letting me send the email via below code to an outside domain email address.  If I run the same code below and send the email to one of our internal domains, it works perfectly. Once i try to send the same email to a outside domain email such as joedoe@gmail.com, i get the dreaded "Could not access 'CDO.Message' object."  Again this code is tested and worked for years, so its not the code, but a setting somewhere which is currently letting me send internal emails but not external emails via this code.  Also if i send the same email using Outlook and not via code, it works with both internal and external addresses. So the problem is specifically only when sending to outside email address via code.

Somewhere there must be a setting on my local PC (ISS settings?), or perhaps the server level which needs to allow code to send emails to outside domains. I hope one of you brilliant troubleshooting can assist, many thanks

Private Function EmailPolicy(ByVal CompId As Integer, ByVal NameRpt As String) As Boolean
Try
Dim Email As String = "mjsXXXX@gmail.com"  ' <-- this is a customer's email not working, if i change to internal email account it works
Dim MessBody As String
Dim NamedInsured  As String = "ZXY"

Dim mail As New MailMessage
mail.To = Email
mail.From = "mxxxxxx@go-xxxxxx.com"      ' <-- this is my domain account
mail.Subject = "Your commercial auto insurance policy............ "
MessBody = "Dear" & " " & NamedInsured & ":" & vbCrLf & vbCrLf
mail.Body = MessBody

Dim Attachment As New MailAttachment("c:\pdf\" & "" & NameRpt & "" & ".pdf")
mail.Attachments.Add(Attachment)
mail.Bcc = "sxxxxxx@go-xxxxxx.com"
SmtpMail.SmtpServer = "172.XX.X.XX"   ' <-- IP of mail server, this is how i had it working at previous site using IP address of email server
SmtpMail.Send(mail)

      Catch ex As Exception
            DisplayWriteError(ex.Message, ex.Source, "frmUnderwriter:EmailCustomer")
        End Try
    End Function
ASKER CERTIFIED SOLUTION
Avatar of Mike Schmidt
Mike Schmidt

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mike Schmidt
Mike Schmidt

ASKER

Works , own solution