Using SMTP_RESULT in an IF Statement

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Dexter1
Pro Scripter
Posts: 64
Joined: Mon Jun 19, 2006 3:28 pm

Using SMTP_RESULT in an IF Statement

Post by Dexter1 » Mon Mar 02, 2009 9:38 pm

I had some troubles with a script using SMTPSendMail caused by an incorrect email address. The script did not fail, it just executed what I told it to but then didn't send the email. I trouble shot this by using MDL>SMTP_RESULT.

But now I would like to check every time the job runs and only display the SMTP_RESULT if the email fails. I tried the following after my email code (with an email address that I know will cause the error) but to no avail. I also tried similar scripts just using the numbers from the SMTP_RESULT message without any luck. Am I missing something?

Code: Select all

if>%SMTP_RESULT%=501 5.5.4 Invalid Address
mdl>Incorrect Email Address
endif
and

Code: Select all

if>SMTP_RESULT=501 5.5.4 Invalid Address
mdl>Incorrect Email Address
endif
Thanks,
Josh

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Mon Mar 02, 2009 10:04 pm

I have found too many different messages and numbers with SMTP. But a successful process has a result of 250

Don't know how much info you need, but here is a simple, slight variation:

Code: Select all

MidString>%SMTP_RESULT%,1,3,vError
If>vError=250,Good

MessageModal>Email Failed.%CRLF%%CRLF%Error info is %SMTP_RESULT%
Goto>Next

Label>Good
MessageModal>Email was successful.

Label>Next
If Email frequently fails, you might consider using SMTP_TIMEOUT and/or a loop to retry email process every "x" seconds for a count of "y" tries.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Dexter1
Pro Scripter
Posts: 64
Joined: Mon Jun 19, 2006 3:28 pm

Post by Dexter1 » Mon Mar 02, 2009 10:31 pm

Ah, perfect.

In the end I used this. Thanks for your help.

Code: Select all

MidString>%SMTP_RESULT%,1,3,vError
If>vError<250>SMTP_RESULT
endif
Thanks,
Josh

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts