Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


CDO Error when sending Email

Posted on 2004-10-22
Medium Priority
Last Modified: 2012-05-05
I get an error when sending emails using CDO. I know this is not uncommon but I think I have narrowed down the issue. I iterate thorugh a group of users calling a Send_Email function with every loop. This opens a CDO object and sends an email. This is the code:

Public Function Send_Email(ByVal strTO As String, ByVal strFROM As String, ByVal strSUBJECT As String, ByVal strMSG As String)
        If ChkValidEmail(strTO) And ChkValidEmail(strFROM) Then
            'Variable which will send the mail
            Dim obj As System.Web.Mail.SmtpMail

            'Variable to store the attachments
            Dim Attachment As System.Web.Mail.MailAttachment

            'Variable to create the message to send
            Dim Mailmsg As New System.Web.Mail.MailMessage
            'Set the properties
            'Assign the SMTP server
            obj.SmtpServer = ""
            'Address of the recipient
            Mailmsg.To = strTO

            'From Address
            Mailmsg.From = strFROM

            'Specify the body format
            Mailmsg.BodyFormat = MailFormat.Html 'Send the mail in HTML Format
           'Mail Subject
            Mailmsg.Subject = strSUBJECT

            'Mail Body
            Mailmsg.Body = strMSG

            'Call the send method to send the mail
        End If
    End Function

This first time through it runs fine and actually every time through seems to be fine but I receive an error on every attempt after the first:

System.Web.HttpException: Could not access 'CDO.Message' object. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException (0x80040211): The message could not be sent to the SMTP server. The transport error code was 0x800ccc0b. The server response was not available

I think the problem is that possibly in the send method a DOEVENTS is included or something similar that continues my code iteration and attempts to send another email while the cdo is already opened sending the previous. I have come to this conclusion when stepping through the project. Is there a way to stop this or that I do a check to make sure it is not opened before I continue and possibly run my own DOEVENTS...

Question by:sesurb
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

Lacutah earned 500 total points
ID: 12387570
Found this problem too....

Apparently, the unmanaged CDO email needs a pause between each iteration to work consistently, I used the following during each iteration:
        ...  [Code for one message] ....
        Dim t As Threading.Thread
        t = Threading.Thread.CurrentThread

The t.Sleep(100) causes the .NET thread to wait 100 Milli-Seconds (1/10 a second), which seems to be enough on my server for it to not throw an exception.  Play with the value for yours (longer / shorter), it's a pain, but that's what we get for using unmanaged resources with .NET managed I suppose!

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question