This is the script I use to send an email when someone presses the doorbell. It is triggered by pressing the doorbell and takes a picture of the person in front of the bell and embeds this message in an email. The part that attaches the photo to the email is a bit complicated because I wanted the photo embedded within the message so it is instantly visible when openening the message without the need to open an attachment. So if you do not need this functionality, the code can be simplified. You do not require any plugin for this script.
Things that you need to specify are:
<hostname of camera>: The host name or ip address of your IP cam
<url to take snapshot>: The url (without the host name) that triggers making a snapshot (this is specific for each type of cam.
<sender address>: The email address used as sender address
<recpient address>: The email address the message must be sent to
<hostname of homeseer>: The host name or ip address of the server running Homeseer. This is required to enable email clients that do not support embedded images to capture the image via the Homeseer web server. Off course this is only possible when you Homeseer server is accessable from the location where you read the email.
<hostname of SMTP mail server>: The host name or ip address of the server (SMTP) you use to send any mail. This is probably a server at your ISP.
Code: Select all
Imports System.Net
Imports System.Net.Mail
Imports System.Net.Mime
Sub Main(parm as object)
Dim sFileName As String
Dim mail As New MailMessage()
Dim htmlView As AlternateView
Dim plainView As AlternateView
Dim now As DateTime
' Get Timestamp
now = DateTime.Now
sFileName = "entrance_" & now.Year & now.Month.ToString() & now.Day.ToString() & "-" & now.Hour.ToString() + now.Minute.ToString() & ".jpg"
' Take pictures
hs.GetURLImage("<hostname of camera>","<url to take snapshot>",false,80,"/html/snapshots/" & sFileName)
' Set the addresses
mail.From = New MailAddress("<sender address>")
mail.To.Add("<recipient address>")
' Set the subject
mail.Subject = "Er wordt gebeld"
' Create the text only part for those readers not able to view HTML with embedded images (only valid when your homeseer server is accessable from where you receive your email)
plainView = AlternateView.CreateAlternateViewFromString("Wie staat er voor de deur?" & vbCrLf & "https://<hostname of homeseer>/snapshots/" & sFilename, Nothing, "text/plain")
' Create the HTML mail with the embedded photo
htmlView = AlternateView.CreateAlternateViewFromString("Wie staat er voor de deur?<br /><img src=cid:deurbel>", Nothing, "text/html")
Dim imageView As New AlternateView(hs.GetAppPath & "/html/snapshots/" & sFileName, MediaTypeNames.Image.Jpeg)
imageView.ContentId = "deurbel"
imageView.TransferEncoding = TransferEncoding.Base64
Dim data As New Attachment(imageView.ContentStream, MediaTypeNames.Image.Jpeg)
data.ContentDisposition.Inline = true
data.ContentId = "deurbel"
data.TransferEncoding = TransferEncoding.Base64
data.Name = hs.GetAppPath & "/html/snapshots/" & sFileName
' Add the views
mail.AlternateViews.Add(plainView)
mail.AlternateViews.Add(htmlView)
mail.Attachments.Add(data)
' Send the message
Dim smtp As New SmtpClient("<hostname of SMTP mail server>")
smtp.Send(mail)
End Sub
Rene.