• Trap invalid email addresses when sending to Outlook

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Trap invalid email addresses when sending to Outlook

    Author
    Topic
    #482804

    I have a routine set up that allows the email addresses contained in a query to be used as the source for an “E-mail Blast”. The routine works perfectly as long as all the email addresses are valid. I’m parsing the email addresses to look for obvious problems, but sometimes they get rejected by Outlook. When this happens, none of the remaining addresses get taken by Outlook, and out of 50 potential recipients, maybe 12 receive the intended email. How can I trap this error from Outlook and have it continue to process the remaining email addresses? I’d also like to generate a list of these invalid email addresses so the user can go back and correct them after.

    To create the list of email addresses, I’m concatenating them (separated by semi-colons) from the query and using the resulting string as the msg.bcc (see below). I’m doing this to ensure we only send mail to 50 recipients at a time which is a restriction placed by the ISP.

    Here’s the code I’m using to send the mail. The email addresses are contained in the variable strMailto which is generated earlier.

    Set Msg = appOutlook.CreateItem(olMailItem)
    With Msg
    .BCC = strMailto
    If Not IsNull(Me.txtcc) Then .BCC = strMailto & “;” & Me.txtcc
    .Subject = strSubject
    .Body = Me.txtBody
    .Attachments.Add (Me.txtFileName)
    .Send
    End With

    Viewing 4 reply threads
    Author
    Replies
    • #1329675

      Well, I solved this myself.
      I added code when parsing the email addresses into the string to have Outlook check each email address individually. I found this link helpful:
      http://www.outlookforums.com/threads/8311-recipient-email-address-is-invalid-but-resolved-property-is-true
      Essentially, I created a new variable called rcpRecipient which I defined as an Outlook.recipient. I then used the following lines to assign a value to that variable and have Outlook check its validity by using the rcpRecipient.Resolve command which allowed me to check the status:
      Set rcpRecipient = appOutlook.CreateItem(olMailItem).Recipients.Add(strEmail)
      rcpRecipient.Resolve
      If rcpRecipient.Resolved = True Then
      strList = strList & “;” & strEmail
      If rcpRecipient.Resolved = false, I add the email address (strEmail) to an error log that the user can access and check later. Works perfectly.

      I’m using Access 2007, in case anyone needs to duplicate this function.

    • #1329676

      Thanks for posting your solution. It looks interesting. I did not know how to do it.

      When it uses Resolve to check its status what is it looking for? What sorts of thing is it finding that your parsing did not find?

    • #1329757

      John:
      In my parsing, I looked for single invalid characters, but an instance of two dots next to each other, for example, would not be caught since a single dot on its own is not invalid. I had considered revising my parsing routine to store the previous character to allow it to look for duplicate spaces or dots, but I’ve actually replaced my parsing routine with this short “resolve” edit since it’s much faster to pass the email address to Outlook and ask it to resolve than parsing through each individual character of an email address looking for invalid characters.

    • #1329759

      Thanks

    • #1329779

      Nice discussion on doing this in regex here.

      cheers, Paul

    Viewing 4 reply threads
    Reply To: Trap invalid email addresses when sending to Outlook

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: