Attaching foscam image to email via lua smtp socket?

I am currently utilizing Lua smtp socket to send email alerts, but would like to add a snapshot from my foscam ip camera. I’ve read people having success doing it, but could not find any examples. Anyone know how I can attach an image to the body of the email via Lua smtp socket?

Here’s the socket I’m speaking of:
http://forum.micasaverde.com/index.php/topic,6153.msg37159.html#msg37159

I am also very interested in sending an image (or multiple) as attachment to a mail when my Foscam detects motion.

I found following link:

which has an example to add an attachment but I can’t seem to get it to work…

hmm… accidentally entered the wrong to address, that’s why it didn’t work ::slight_smile:

just did some initial tests and the last example in the link I posted shows an inline image, I did have to add the path in the io.open line…

gonna play some more with this :slight_smile:

were you able to get this fully functioning?

Yeah… Currently you can define the number of images and the time between them.
Been meaning to post the code but got side tracked…
Will try to do so the following days…

Sent from my SGSII CM10 with Tapatalk 2

Thanks! Please share when you can as I’ll be looking forward to it!

Hi

Any chance you can post the code here that you used?

I am also curious to understand how it will work.
Thanks

I just created this luup script to do it - attach a picture from an IP camera registered as a device on Vera. Now you only have to create a scene with this luup script and setup the desired triggers.

I’m using SMTP2Go as a free SMTP server (20 free e-mails per day). There you can setup an e-mail address that doesn’t need to authenticate to send the e-mails via SMTP, which is required by this code.

This is the raw code:

local veraIP = "<Vera IP>" -- Please let me know if there is an automagic way to get it.
local cameraID = 45 -- The IP camera device ID on Vera.
local ltn12 = require("ltn12")
local mime = require("mime")
local smtp = require("socket.smtp")

local result, content = luup.inet.wget("http://" .. veraIP .. ":3480/data_request?id=request_image&cam=" .. cameraID)

local attachment = ltn12.source.chain(
  ltn12.source.string(content),
  ltn12.filter.chain(
    mime.encode("base64"),
    mime.wrap()
  )
)

local source = smtp.message({
  headers = {
     from = "Vera <sender@domain.com>",
     to = "Recipient <recipient@gmail.com>",
     subject = "Here is a picure from your webcam"
  },
  body = {
    preamble = "Hello Recipient, \r\n" ..
               "This is your e-mail with a picture attached.",
    [1] = { 
      headers = {
        ["content-type"] = 'image/jpeg; name="image.jpg"',
        ["content-disposition"] = 'attachment; filename="image.jpg"',
        ["content-description"] = 'Camera picture',
        ["content-transfer-encoding"] = "BASE64"
      },
      body = attachment
    },
    epilogue = "That's it folks! :)"
  }
})

r, e = smtp.send{
  from = "sender@domain.com",
  rcpt = "recipient@gmail.com",
  source = source,
  server = "smtpserver.com",
  port = 2525
}

Sources of information used when creating this code (leaving it here for future reference):
http://wiki.micasaverde.com/index.php/Luup_Requests
https://github.com/diegonehab/luasocket/blob/master/etc/get.lua

http://wiki.micasaverde.com/index.php/Luup_Scenes_Events
http://forum.micasaverde.com/index.php/topic,3662.msg17918.html

http://forum.micasaverde.com/index.php/topic,24018.0.html
http://w3.impa.br/~diego/software/luasocket/old/luasocket-2.0-beta/smtp.html

The Vera Alerts Plugin provides this … and a lot more.
You can send Pictures via Vera Alerts Mobile (Android), SMTP, and BushBullet (Multiple Platforms).

Hi vinicius.vbf

Thanks for your code, really nice

initially i did not work for me but later i found out that i had to use server = “smtpcorp.com

thanks!

@vinicius.vbf: Thanks for your work on this. I have my own mail server so no worries about a limit.
Working on door sensors and PIR sensors install and can use this to have the right cam send an image or images if they fire…

I am trying to use the same.Tried Vera alert but with no sucess to get pic from Foscam 9818W. Tried the code you wrote but i am getting lua error in it. Can you give proper code you used.

Thanks

[quote=“vinicius.vbf, post:8, topic:171076”]I just created this luup script to do it - attach a picture from an IP camera registered as a device on Vera. Now you only have to create a scene with this luup script and setup the desired triggers.

I’m using SMTP2Go as a free SMTP server (20 free e-mails per day). There you can setup an e-mail address that doesn’t need to authenticate to send the e-mails via SMTP, which is required by this code.

This is the raw code:

local veraIP = "<Vera IP>" -- Please let me know if there is an automagic way to get it.
local cameraID = 45 -- The IP camera device ID on Vera.
local ltn12 = require("ltn12")
local mime = require("mime")
local smtp = require("socket.smtp")

local result, content = luup.inet.wget("http://" .. veraIP .. ":3480/data_request?id=request_image&cam=" .. cameraID)

local attachment = ltn12.source.chain(
  ltn12.source.string(content),
  ltn12.filter.chain(
    mime.encode("base64"),
    mime.wrap()
  )
)

local source = smtp.message({
  headers = {
     from = "Vera <sender@domain.com>",
     to = "Recipient <recipient@gmail.com>",
     subject = "Here is a picure from your webcam"
  },
  body = {
    preamble = "Hello Recipient, \r\n" ..
               "This is your e-mail with a picture attached.",
    [1] = { 
      headers = {
        ["content-type"] = 'image/jpeg; name="image.jpg"',
        ["content-disposition"] = 'attachment; filename="image.jpg"',
        ["content-description"] = 'Camera picture',
        ["content-transfer-encoding"] = "BASE64"
      },
      body = attachment
    },
    epilogue = "That's it folks! :)"
  }
})

r, e = smtp.send{
  from = "sender@domain.com",
  rcpt = "recipient@gmail.com",
  source = source,
  server = "smtpserver.com",
  port = 2525
}

Sources of information used when creating this code (leaving it here for future reference):
http://wiki.micasaverde.com/index.php/Luup_Requests
https://github.com/diegonehab/luasocket/blob/master/etc/get.lua

http://wiki.micasaverde.com/index.php/Luup_Scenes_Events
http://forum.micasaverde.com/index.php/topic,3662.msg17918.html

http://forum.micasaverde.com/index.php/topic,24018.0.html
http://w3.impa.br/~diego/software/luasocket/old/luasocket-2.0-beta/smtp.html[/quote]

I 'am using alsoo a gmail account

I have tried to send a picture to my gmail adress with Vera alerts but did not succeed.

Could anyone help me on this problem?

I Have recently bought a vera edga, and I’m trying to now send notifications with screenshot.