Solved

CDO Message + trap invalid mail addresses

Posted on 2004-08-23
13
468 Views
Last Modified: 2008-01-09
Hi.

I use CDO to send activation codes to new members of my password protected site. Now, sometimes people get funny and submit addresses that don't exist, meaning I get a "Mail not delivered" mail back. Sometimes I need to remind people that haven't activated their accounts that they should do so, meaning I've written a script that takes stuff out of the database and mails a reminder to the members who haven't activated their account. But if someone has entered a faulty mail address, the script of course stops givng me an error and stops the execution.

I somehow need to trap this event and just skip that particular mail and jump to the next.

How is this done?
0
Comment
Question by:bobamatics
  • 8
  • 5
13 Comments
 
LVL 31

Expert Comment

by:alorentz
ID: 11876221
Send email through regex first:

Function RegExpTest(sEmail)
  RegExpTest = false
  Dim regEx, retVal
  Set regEx = New RegExp

  ' Create regular expression:
  regEx.Pattern ="^[\w-\.]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,3}$"

  ' Set pattern:
  regEx.IgnoreCase = true

  ' Set case sensitivity.
  retVal = regEx.Test(sEmail)

  ' Execute the search test.
  If not retVal Then
    exit function
  End If

  RegExpTest = true
End Function

If it returns tru then it is good, and you should send.  This check email address format, not whether the address exists.  No easy to check if exists.
0
 

Author Comment

by:bobamatics
ID: 11876253
I already have a function to check if the address is in a valid format, what I need is being able to trap when the script halts due to the error given by the mail server.

The error is 8004020f and means "The transport failed to connect to the server." which in this case means it couldn't be sent because the mail address doesn't even exists.
0
 
LVL 31

Expert Comment

by:alorentz
ID: 11876260
Don't think ASP will do that...
0
 
LVL 31

Expert Comment

by:alorentz
ID: 11876268
Using "on error resume next" will not work in this situation either.  however this error should not stop the script, it will effect SMTP and badmail, but the script should continue.
0
 
LVL 31

Accepted Solution

by:
alorentz earned 100 total points
ID: 11876277
CDO script doesn't care if the email doesn't exist.  SMTP will just send to badmail, and may send Admin email to your domain account.  But ASP should run through all names in DB.
0
 

Author Comment

by:bobamatics
ID: 11876335
Ok, I tried to mail to an address I know doesn't exist, and you're right, it sends it anyway.

But then I have no idea why it halts at certain addresses. Seems there not much I can do about it then?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 31

Expert Comment

by:alorentz
ID: 11876417
No idea why it would halt?

Maybe on nulls, or if there's a space in the address.  But if there anything else in it "jdoe@jdoe.com", "sss", whatever, it will not stop the script.  Check for nulls or spaces in the email.
0
 

Author Comment

by:bobamatics
ID: 11876517
That's the thing, I ran the script four times with slight modifications inbetween and got the error message. Then I checked my inbox and saw four "Undelivered Mail Returned to Sender" mails.

I do trim(strEmail) when I put in the address in the database...so it should send them. Is there a limit on how many requests a mail server will accept at once or something? I use my ISP:s SMTP server and try to loop 30 mails in the execution of the page.
0
 
LVL 31

Expert Comment

by:alorentz
ID: 11876546
Yes, they may block the amount of email that can be sent...to prevent spamming.  Many ISP's do check for this sort of thing.

However, TRIM won't work on somthing like this "jdoe@ jdoe.com".  That will kill the script because of the internal space.

But, most likely this is a problem because you ISp is not allowing all those emails at the same time.  MAy want to limit to 10 or so.
0
 

Author Comment

by:bobamatics
ID: 11876581
Now I Response.Wrote the id:s after the mails had been sent and checked where it stopped. And it stopped mostly on faulty addresses, like whatever@hotmail.co (isn't co a top domain?) and _blah_@domain.com where _ isn't allowed as a starting character. But liiiinda@hotmail.com wasn't accepted. Very strange.

Oh well, I've got most of the mails away now, and your answer was correct so have the points and thanks for your time and help :)
0
 
LVL 31

Expert Comment

by:alorentz
ID: 11876637
Good luck!
0
 

Author Comment

by:bobamatics
ID: 11876652
Isn't it strange that it halts on michel_kt@hotail.com if it doesn't know that doesn't exists? Just wondering...it clearly looks like a misspelling to me.
0
 
LVL 31

Expert Comment

by:alorentz
ID: 11876684
I still don't know why the script would stop, but CDO may validate on domain name. MS may have incorporated this functionality into the new CDOSYS component.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

932 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now