Results 1 to 3 of 3

Thread: Sending Emails with CDO, how to catch problem emails?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    105

    Sending Emails with CDO, how to catch problem emails?

    I have an automatic email function in my app, and the code looks like:
    Code:
    formAllEmails.MousePointer = vbHourglass
            
            'setup for email
            Set objemail = CreateObject("CDO.Message")
            objemail.From = emailDisplayName & "<" & emailAddressDB & ">"
            objemail.To = p_email
            '***************
            'needs to chang to check type, then send appropriate message
            '***************
            objemail.Subject = "An update on from " & emailDisplayName
            objemail.TextBody = message
            objemail.Configuration.Fields.Item _
            ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
            
            'Name or IP of Remote SMTP Server
            objemail.Configuration.Fields.Item _
            ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = emailServer
            
            'Type of authentication, NONE, Basic (Base64 encoded), NTLM
            objemail.Configuration.Fields.Item _
            ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
            
            'Your UserID on the SMTP server
            objemail.Configuration.Fields.Item _
            ("http://schemas.microsoft.com/cdo/configuration/sendusername") = emailAddressDB
            
            'Your password on the SMTP server
            objemail.Configuration.Fields.Item _
            ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = emailPassword
            
            'Server port (typically 25)
            objemail.Configuration.Fields.Item _
            ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = emailPort
            
            'Use SSL for the connection (False or True)
            If emailSSL = "1" Then
                objemail.Configuration.Fields.Item _
                    ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
            Else
                objemail.Configuration.Fields.Item _
                    ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
            End If
            
            'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
            objemail.Configuration.Fields.Item _
            ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 30
            
            objemail.Configuration.Fields.update
            
            '==End remote SMTP server configuration section==
            
            
            objemail.Send
            formAllEmails.MousePointer = temp
        End If
        Exit Sub
    hell:
        formAllEmails.MousePointer = temp
        If Err.Number = -2147220973 Then
            MsgBox "The server could not make the connection to your email account. Please check the information and try again"
        Else
            MsgBox "An internal error occurred. Error code: 4000-" & Err.Number & Err.Description
        
        End If
    But the problem is this: when I am sending more than one message out if there is a problem with the email address (mailbox full, bad addy, etc) how can I keep sending all the others? I dont want to abort the process because of one bad addy or one box that is full or ...

    thoughts?

    Also, does anyone have a list of CDO error codes?
    EDIT: found the codes: http://www.cdolive.com/cdo11.htm

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Nov 2006
    Posts
    105

    Re: Sending Emails with CDO, how to catch problem emails?

    would it make sense to just put an error catching statement right under the "objemail.Send" line? That would catch email error codes, but that would only work if i removed the "on error goto" section at the top, right?

  3. #3
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Sending Emails with CDO, how to catch problem emails?

    You could perform some in-line error checking
    Code:
            On Error Resume Next ' Turn in-Line Error Handling On
            objemail.Send
            If Err.Number <> 0 Then ' If it failed, report the error
                MsgBox "Sending to " & p_email & " Failed. Error Code: " & Err.Number
            End If
            On Error GoTo  hell ' Restore original Error Handler
            formAllEmails.MousePointer = temp

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width