AdvancedHMI Software
General Category => Support Questions => Topic started by: Allan19111911 on November 29, 2016, 10:10:09 PM
-
Hello all, i have got the "sending email by bit working now" is there a way to include variables in the message ? ie, The temp of the water is (n7:0) I'm using the EthernetIPforSLCMicroCom1 driver
Thanks'
Allan
-
The Emailer component is very basic and does not give a way to do anything like that. You can use a DataSubscriber and send an email via code as shown in this topic:
http://advancedhmi.com/forum/index.php?topic=796.msg3858#msg3858
You can then modify the line of code:
email.Body = "This event occurred"
to something like this:
email.Body = "The Temp of the water is " & EthernetIPforSLCMicroCom1.Read("N7:0")
-
worked first time, thank you so much
here is the code i used to get gmail to work, I pieced it together from a few different sources. It requires gmail to have an app password through 2 step verification
i am not very good with vb so dont laugh if there is mistakes,,, i am good at cut and paste
Private Sub DataSubscriber1_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber1.DataChanged
'* 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
Try
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
SmtpServer.EnableSsl = True
SmtpServer.Credentials = New _
Net.NetworkCredential("youremailaddress@gmail.com", "apppassword")
SmtpServer.Port = 587
SmtpServer.Host = "smtp.gmail.com"
mail = New MailMessage()
mail.From = New MailAddress("someone@gmail.com")
mail.To.Add("someone@yahoo.com")
mail.Subject = "Test Mail"
mail.Body = "The Temp of the water is " & EthernetIPforSLCMicroCom1.Read("N7:0")
SmtpServer.Send(mail)
MsgBox("mail send")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End If
End If
End Sub
-
Thanks for posting your solution. A while back I tried with Gmail, it worked once, then would not work again so I gave up on it.
-
hi archie, One more question, is there any way to get multiple lines and variables in the body
ie
mail.Body = "The Temp of the water is " & EthernetIPforSLCMicroCom1.Read("N7:0")
"The depth of the water is "& EthernetIPforSLCMicroCom1.Read("N7:1")
" water flow is "& EthernetIPforSLCMicroCom1.Read("N7:1")
I tried this but get errors,
if i put mail.body in front of all of them i only get the last one.
thanks
Allan
-
Try something like this:
mail.Body = "The Temp of the water is " & EthernetIPforSLCMicroCom1.Read("N7:0") & Environment.NewLine & _
"The depth of the water is "& EthernetIPforSLCMicroCom1.Read("N7:1") & Environment.NewLine & _
" water flow is "& EthernetIPforSLCMicroCom1.Read("N7:1")
-
You can't just put a new line in your code to get it to treat it as a new line in a string. One way to add a new line is to use Environment.NewLine
mail.Body = "The Temp of the water is " & EthernetIPforSLCMicroCom1.Read("N7:0") & Environment.NewLine &_
"The depth of the water is "& EthernetIPforSLCMicroCom1.Read("N7:1") & Environment.Newline & _
" water flow is "& EthernetIPforSLCMicroCom1.Read("N7:1")
Well shoot, too slow...
-
thanks everyone
-
I tried the above approach, but it seems to only read the values when the application is started, not when the emailer is activated. (So whenever the emailer sends an email, the values sent are the values from when the application was started that day.)