Results 1 to 6 of 6
  1. #1
    Star Lounger
    Join Date
    Jan 2008
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Trap invalid email addresses when sending to Outlook

    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

  2. #2
    Star Lounger
    Join Date
    Jan 2008
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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...operty-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(s trEmail)
    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.

  3. #3
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    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?
    Regards
    John



  4. #4
    Star Lounger
    Join Date
    Jan 2008
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  5. #5
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    Thanks
    Regards
    John



  6. #6
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    8,170
    Thanks
    47
    Thanked 980 Times in 910 Posts
    Nice discussion on doing this in regex here.

    cheers, Paul

Posting Permissions

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