Author Topic: Emailer send values  (Read 2550 times)

g.mccormick

  • Newbie
  • *
  • Posts: 29
    • View Profile
Emailer send values
« on: February 19, 2018, 09:58:25 PM »
I seemingly have the emailer working to send an email to my gmail account.  I would like to include  values in the email message.  I am using modbustcp comms.  How can I send the value of a modbus register or two included in my email message?

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Emailer send values
« Reply #1 on: February 19, 2018, 11:13:12 PM »

g.mccormick

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: Emailer send values
« Reply #2 on: February 20, 2018, 08:58:47 AM »
Thanks.

Dumb question as  I have 0 VB knowledge, where do I put that data subscribe code?

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Emailer send values
« Reply #3 on: February 20, 2018, 09:22:12 AM »
Archie has listed steps in this topic: http://advancedhmi.com/forum/index.php?topic=796.msg3858#msg3858

When you add DataSubscriber to the form then just double-click it to get to the code area.

g.mccormick

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: Emailer send values
« Reply #4 on: February 20, 2018, 10:37:30 AM »
Sweet.  I had to actually use the code from Allan in this thread
http://advancedhmi.com/forum/index.php?topic=1537.0

to get it to work. 

Two more dumb questions.  1. in the msgbox popup, how would I print the value of the mail.to.add ?? 
2. Is there a way that you could use a case statement based on the value of an integer to decide what message to send?  Or would it be easier to just have multiple datasubscribes each setup with different messages for different alarm/notify messages?

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Emailer send values
« Reply #5 on: February 20, 2018, 05:04:27 PM »
These are my guesses:

2. If your DataSubscriber's PLCAddressValue is set to monitor an integer value then you can try using a case statement similar to this:

            Select Case CInt(e.Values(0))
                        Case 0 : mail.Body = "The Temp of the water is " & ModbusTCPCom1.Read("40001")
                        Case 1 : mail.Body = "The Pressure is " & ModbusTCPCom1.Read("40002")
                        Case 2 : mail.Body = "You have just won $" & ModbusTCPCom1.Read("40002")
            End Select

1. If it is only 1 recipient that messages would be sent to then: MsgBox("mail sent to: " & mail.To(0).ToString)
    More than 1 recipient then you have to base it on something, maybe e.Values(0): MsgBox("mail sent to: " & mail.To(CInt(e.Values(0))).ToString)
    These could be a part of the case statement.

g.mccormick

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: Emailer send values
« Reply #6 on: February 20, 2018, 05:22:36 PM »
Awesome thanks for the help.

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Emailer send values
« Reply #7 on: February 20, 2018, 05:41:16 PM »
When it comes to coding you can put whatever you want in it (for as long as you make it work in the end).

Here is the part that you might change if you will be using case statement:

        '* Make sure Data came back
        If e.Values IsNot Nothing AndAlso e.Values.Count > 0 Then
            '* Did it come back as True or 1?
            If String.Compare(e.Values(0), "TRUE", True) = 0 Or e.Values(0) = "1" Then

possibly change it to:

        '* Make sure Data came back
        If e.Values IsNot Nothing AndAlso e.Values.Count > 0 Then
            '* Are the values between 0 and 3?
            If CInt(e.Values(0)) >=0 AndAlso CInt(e.Values(0)) <=3 Then

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Emailer send values
« Reply #8 on: February 20, 2018, 06:07:03 PM »
Here is a bit more info for you:

The mail.To is a collection of mail addresses.
If you will be adding more than 1 recipient when this code is run, they will be stored as: mail.To(0), mail.To(1), ...
If you will be adding only 1 recipient when this code is run, regardless of who the recipient is based on the case statement, it will be stored as mail.To(0) always.

Because the mail is re-created every time the code is run, it will not be memorizing the recipients.

g.mccormick

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: Emailer send values
« Reply #9 on: February 20, 2018, 08:34:30 PM »
 Ok so if I wanted to send the email to different people based onthe the value of int, I would specify the mail.to.add in each case then?   Thanks for the info.

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Emailer send values
« Reply #10 on: February 20, 2018, 10:17:06 PM »
When the code is run only 1 case statement should be processed (unless you somehow create a code that should do different).

Within the case statement being processed, you can send that particular message to either 1 or more recipients.
Your message box can have multiple recipients printed: MsgBox("mail sent to: " & mail.To(0).ToString & " , "  & mail.To(1).ToString ...)

So, you should have mail.To.Add in each case.