E-mail configuration

[B]Hello, I have an opto22 SNAP-UP1-D64. I did a program with IoControl and I did the HMI with IoDisplay. I would like that the opto22 send a e-mail when an alarm occurs that is to say when a digital point has as value 1. How can I do? I have seen that I can use the scratch pad bit but I have not understood. Can you help me? [/B]
[B]An example for e-mail sending ?[/B]

[B]Thanks a lot [/B]

[B]Best regards [/B]
[B]Infrabel[/B]

[B]Belgium[/B]

I would also like a “dummies” guide to using the scratch pad bit. I have worked out that it is in binary and you have to match the 16-zero’s to the modules and the value of that zero being 1,2,4,6 etc for the module depending on the module # and the IO point #. It’s all confusing!!

While the scratchpad is the main way to send an email, its not the only way…
There are two others;

  1. Drive the scrachpad manually. This involves setting the memory map locations in your chart and calling the event from your chart when you want the email sent. It works, and while its a step above working in the memmap, its not very elegant. (For example, you have to set the IP address of the email server in HEX).
    Better is method number two…

  2. Use a chart to talk to your email server.
    This is very powerful as we are all pretty used to working in charts and they are nice and easy to debug.
    Here is some code that we have been working with on and off for a little while.
    It works, but I cant support it, that said, its probably worth you trying it.

Here is what the basic chart looks like;

As you can see, we simply check for a digital input (or an analog condition, or a variable going true or false or a…).
If its true, we check to see if we have sent an email once already. If not (as is the case the first time around), then send an email and set a variable true so that next time around, when the point is still on, the variable says, hey, we have already sent one email, don’t send another. (This is really really really important, you don’t want to send 1000’s of emails just cause the point is still on… ask me how I know this…)
To send the email, we load up a few addresses, here is whats in that block;

email servers IP address. Change to match yours.
Move String
From: 192.168.1.1
To: email_server_ip_address_string

Who the message is from:
Move String
From: someone@domain.com
To: email_from_address_string

who you are sending the email to
Move String
From: mrsmith@domain.com.au
To: email_to_address_string

subject:
Move String
From: email subject for alarm 1
To: email_subject_string

body:
Move String
From: Email from a chart… How cool is that??
To: email_body_string

this is a very important step, it prevents you from sending 1000+ emails while the alarm point is in alarm. The email chart will set the flag true once the email has been sent, the user sets it false when the alarm is not longer active.
Move to Pointer
Object: email_alarm_1_sent_flag
Pointer: email_complete_ptr

Now, the good stuff…
Here is the code that is in the OptoScript block, the stuff that does all the talking to your email server…



  email_status_string = "";

  email_status_ok_continue_flag = 1; // set email_status_ok_continue_flag to true

  email_temp_string = "tcp:" + email_server_ip_address_string + ":25";

  SetCommunicationHandleValue(email_temp_string, email_server_com_handle);

  email_status_flag = OpenOutgoingCommunication(email_server_com_handle);

  email_server_delay = 0; // initialize the counter
    repeat 
    DelayMSec(100); // do a little loop waiting for the email server to answer our request.

    email_server_delay = email_server_delay + 1; // increment the counter
  until (email_server_delay >= 100) or (GetNumCharsWaiting(email_server_com_handle) > 0); // Either time out or the email server will answer.

  // Check the connection and receive the greeting
  if (0 == email_status_flag) then
    email_status_ok_continue_flag = 0; // assume an error

    if (GetNumCharsWaiting(email_server_com_handle) > 0) then
      DelayMSec(delay_short); 
      email_status_flag = ReceiveString(email_temp_string, email_server_com_handle);
       

      if (0 == email_status_flag) then
        if (FindSubstringInString("220", 0, email_temp_string) >= 0) then
          email_status_ok_continue_flag = 1;
        else
          email_status_string = email_temp_string;
        endif
      endif
    else
      email_status_string = "Unable to connect to email server";
    endif
  else
    email_status_string = "Unable to connect to email server";
  endif

  // Send Greeting
  if (email_status_ok_continue_flag) then

    GetControlEngineAddress(email_temp_string);

    email_send_string = "HELO " +  email_temp_string + Chr(13) + Chr(10);

    email_status_flag = TransmitString(email_send_string, email_server_com_handle);
    
    if (0 == email_status_flag) then
      if (GetNumCharsWaiting(email_server_com_handle) > 0) then
        email_status_flag = ReceiveString(email_temp_string, email_server_com_handle);

        if (0 == email_status_flag) then
          if (FindSubstringInString("250", 0, email_temp_string) >= 0) then
            email_status_ok_continue_flag = 1;
          else
            email_status_string = email_temp_string;
          endif
        endif
      endif
    endif
  endif


  // Send MAIL FROM
  if (email_status_ok_continue_flag) then
    email_status_ok_continue_flag = 0; // assume an error

    email_send_string = "MAIL FROM:" + email_from_address_string + Chr(13) + Chr(10);

    email_status_flag = TransmitString(email_send_string, email_server_com_handle);
    
    if (0 == email_status_flag) then
      if (GetNumCharsWaiting(email_server_com_handle) > 0) then
        email_status_flag = ReceiveString(email_temp_string, email_server_com_handle);
        if (0 == email_status_flag) then
          if (FindSubstringInString("250", 0, email_temp_string) >= 0) then
            email_status_ok_continue_flag = 1;
          else
            email_status_string = email_temp_string;
          endif
        endif
      endif
    endif
  endif


  // Send RCPT TO:
  if (email_status_ok_continue_flag) then
    email_status_ok_continue_flag = 0; // assume an error

    email_send_string = "RCPT TO:" + email_to_address_string + Chr(13) + Chr(10);

    email_status_flag = TransmitString(email_send_string, email_server_com_handle);
    
    if (0 == email_status_flag) then
      if (GetNumCharsWaiting(email_server_com_handle) > 0) then
        email_status_flag = ReceiveString(email_temp_string, email_server_com_handle);
        if (0 == email_status_flag) then
          if (FindSubstringInString("250", 0, email_temp_string) >= 0) then
            email_status_ok_continue_flag = 1;
          else
            email_status_string = email_temp_string;
          endif
        endif
      endif
    endif
  endif


  // Send DATA
  if (email_status_ok_continue_flag) then
    email_status_ok_continue_flag = 0; // assume an error

    email_send_string = "DATA" + Chr(13) + Chr(10);

    email_status_flag = TransmitString(email_send_string, email_server_com_handle);

    if (0 == email_status_flag) then
      if (GetNumCharsWaiting(email_server_com_handle) > 0) then
        email_status_flag = ReceiveString(email_temp_string, email_server_com_handle);
        if (0 == email_status_flag) then
          if (FindSubstringInString("354", 0, email_temp_string) >= 0) then
            email_status_ok_continue_flag = 1;
          else
            email_status_string = email_temp_string;
          endif
        endif
      endif
    endif
  endif

  // Send Subject, To, From, etc.
  if (email_status_ok_continue_flag) then
    email_send_string = "Subject:" +  email_subject_string   + Chr(13) + Chr(10) + 
            "To:"      + email_to_address_string   + Chr(13) + Chr(10) + 
            "From:"    + email_from_address_string + Chr(13) + Chr(10) + Chr(13) + Chr(10);

    email_status_flag = TransmitString(email_send_string, email_server_com_handle);

    if (0 <> email_status_flag) then
      email_status_ok_continue_flag = 0;
    endif
  endif

  // Send Subject, To, From, etc.
  if (email_status_ok_continue_flag) then
    email_send_string = email_body_string + Chr(13) + Chr(10);

    email_status_flag = TransmitString(email_send_string, email_server_com_handle);

    if (0 <> email_status_flag) then
      email_status_ok_continue_flag = 0;
    endif
  endif


  // Send end of data
  if (email_status_ok_continue_flag) then
    email_status_ok_continue_flag = 0; // assume an error

    email_send_string = Chr(13) + Chr(10) + Chr(46) + Chr(13) + Chr(10);

    email_status_flag = TransmitString(email_send_string, email_server_com_handle);
 
    if (0 == email_status_flag) then
      if (GetNumCharsWaiting(email_server_com_handle) > 0) then
        email_status_flag = ReceiveString(email_temp_string, email_server_com_handle);
        if (0 == email_status_flag) then
          if (FindSubstringInString("250", 0, email_temp_string) >= 0) then
            email_status_ok_continue_flag = 1;
          else
            email_status_string = email_temp_string;
          endif
        endif
      endif
    endif
  endif


  if (email_status_ok_continue_flag) then
    email_status_string = "Message Sent";
    SetVariableTrue(*email_complete_ptr);
  endif

  CloseCommunication(email_server_com_handle);



That should get you up and running.
The nice thing about sending email from a chart using this code is that it can be set from FactoryFloor controllers or newer.

There is one major ‘got-ya’ for any method that you might chose to use when sending emails from the controller with firmware versions less than v9.1…
There is no way to enter a user name or password to authenticate with the email server.
This means you might need to talk with your IT guys and get them to whitelist the IP address of the controller sending the email. This means that they allow the IP address to relay emails from the controller without authentication.
If your controller is not on the same domain as the email server, and you want to use one out on the web, like yahoo or gmail, then there is only one thing I can suggest… subscribe to ‘OptoNews’ and wait… We might have a solution in the works…

In the mean time… Code on!

[U]thebaldgeek[/U]
[U][/U]
Thanks for everyting

I test it

Infrabel-Belgium

I’ll see what I can do with this one. Thanks Ben! Just a bit off-topic, do you think this will also fly with SNMP? Or does SNMP really really have to go through the scratch pad bits? I’ve tried it out and I got it working but it’s still finicky…

Since 9.1 PAC Project was just released, I have to share this link to a SendEmail example chart where we show you how you might use the new-in-9.1 SendEmail PAC Control command! Whoo-hoo! We’re excited.

There are also HTTP Get and HTTP Post commands… read the whole list here.

On the question of the Scratch Pad Bits, for those of you using strategies, you might find that setting these bits is easier to in a chart (I prefer OptoScript blocks). For example, using the Scratch Pad commands. The Event Message commands may be of use too, especially for the SNMP users out there.

Keep on coding!
-OptoMary

Hello,
I want to have a table on the body of the e-mail!
Have anyone an idea how to make it?
Thank you.

Hi Vtrikola,

Welcome to the OptoForums! Be sure to check out this example chart. (From PAC Control’s config mode, select Chart > Import… then select the file from where you downloaded and extracted it on your PC.)

You’ll see in the example chart and in the help text for this Communication > Send Email command that a string table is what you fill in to pass to that command. So, the body of your email is already a table – it’s up to you to decide what to put in it.

Could you tell us more about exactly what you’d like in that email? Perhaps numbers with commas between them? Perhaps you could show us an example of what it would look like, and what types of variables you currently have that data stored in?

Don’t forget, Product Support is FREE and they’d be happy to help too.

-OptoMary

SendEmail chart gives me a -43 error when sending txt message from a table of cell phone numbers. If the table contains only on cell number, it works fine but not with several numbers in the table. Can you test if you see same results?

Controller: EB2 with softpack running on windows 7

Tim,

Are you using the chart, or the PAC Control commands to send the email from the SoftPAC Controller?

I would not be using the sample chart, that’s only for older controllers.
The new PAC Control commands will send from a table just fine, numbers or or not. (Tested many times).

Ben.

Ben,

I am using PAC Control commands. Found out that txt message cannot be delivered to one of the cell numbers and loops repetedly - this stops delivering the message to other cell numbers in the table. For now, I removed the cell number from the table and have not seen the -43 errror message yet.

I am testing using PAC Display Email feature to send alarm messages. Perhaps this is more stable than sendemail command in PAC Control.

Tim

Hi Tim,

If you’re using SoftPAC + PAC Control commands, then the underlying (Windows) mechanism should be very similar to what our PAC Display Email feature uses.

In any case, if there is a problem with the SendEmail command, we’d like to get to the bottom of it. Have you contacted our Product Support team about this one, I hope?

Thanks,
Mary