Host Engineering Forum

General Category => Do-more CPUs and Do-more Designer Software => Topic started by: OrionHE on June 05, 2018, 06:09:58 PM

Title: Email Instruction has unexpected (by me) behavior.
Post by: OrionHE on June 05, 2018, 06:09:58 PM
I read up, but failed to find an official explanation for this. Feel free to point me to the appropriate documentation.

I use the EMAIL instruction with a String variable in the "To" field that is a concatenation of up to three email addresses, set in the HMI. Recently, I discovered that if none of the email addresses are entered, the EMAIL instruction will not give me an Error, but it won't give me a Success either.

This is a problem, since I set up the program to branch off in one of two cases, Success or Error. Neither happened, and an important operation was skipped over.

Personally, I would be happy to see an error here. Maybe "Could not send email: no valid email address in 'To' field", or something like that. As it stands, I'll have to make a secondary timeout and consider it an error. But I had hoped that "On Error" would have covered that.

I'm happy to hear other thoughts on this. Thanks for listening.
Title: Re: Email Instruction has unexpected (by me) behavior.
Post by: BobO on June 05, 2018, 08:53:34 PM
Explanation? Sounds like a bug. Until we can fix it, I would validate the field myself.
Title: Re: Email Instruction has unexpected (by me) behavior.
Post by: OrionHE on June 06, 2018, 04:14:03 PM
But how do you validate an optional field that is left blank?

My current biggest issue is the EMAIL instruction won't timeout and give me an error. I've set a backup "timeout" timer to end the program that triggers the EMAIL, but then when the program dies I get an ST147 and the EMAIL instruction won't work (even with a valid email address) until the PLC is rebooted.

I really just need the EMAIL instruction to give me a success or error. I'm stuck in limbo.
Title: Re: Email Instruction has unexpected (by me) behavior.
Post by: BobO on June 06, 2018, 04:59:30 PM
But how do you validate an optional field that is left blank?

"To:" is not optional.

You're using a variable, right? Do a STRTRIM on the variable prior to starting EMAIL. A valid email address will need at least 3 characters and one will need to be '@'. Check the length using the string struct field ".Length". Do a STRFIND to check for the '@'. If either of those two are missing, your email address is invalid, so don't try to send the email.

My current biggest issue is the EMAIL instruction won't timeout and give me an error. I've set a backup "timeout" timer to end the program that triggers the EMAIL, but then when the program dies I get an ST147 and the EMAIL instruction won't work (even with a valid email address) until the PLC is rebooted.

I really just need the EMAIL instruction to give me a success or error. I'm stuck in limbo.

Again, it's a bug. We'll fix it, but it will take a little while to do that. The validate I described above should prevent the issue. I haven't tested this, but you should be able to kill an EMAIL by killing the program it is in. When I'm sending an EMAIL, I always put it in it's own program block anyway. So RUN the program, validate the "To:" address in some stages prior to a stage containing the EMAIL. If the program hasn't completed in some maximum time, HALT the program. The system should free the device and clean up. You'll get a warning, but don't worry about it.
Title: Re: Email Instruction has unexpected (by me) behavior.
Post by: OrionHE on June 06, 2018, 05:11:43 PM
Thanks for the validate suggestion. My solution was to populate any empty string variables that are concatenated in the "To:" field with "Enter valid email address". This serves as a prompt to the user, should they ever visit that particular screen. The EMAIL instruction errors with these values and everything is grand.

I did find myself looking for the ability to CLOSE the SMTP_Client device programmatically, but couldn't seem to find a way to do that.
Title: Re: Email Instruction has unexpected (by me) behavior.
Post by: BobO on June 06, 2018, 05:13:56 PM
I just tried it with something that should be pretty close to what we released today (2.3.0). I am getting an error with an empty "To:" variable, at least from the SMTP server. It's not exactly what I'd like to see, but it does not appear to be hanging.