This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

email with attachement gives image size 0
#11
(11.07.2018, 18:21)mlaudren Wrote: Can you try to add a fake parameter in the url like timestamp.
http://user:pass@CAMERAIP/cgi-bin/snapshot.cgi?1&ts=randomnumber

If it worked 1 time, and then fail, maybe there is a caching issue. By adding a parameter that change in the url, it is consider as a new request and will not look in the cache if any.

Thanks!! this random number works perfectly. But with the script don´t attach the image correctly.. can you help me with the script?

Event-Based Script:

mail('MyEmail', 'ALERTA', '¡¡¡Alguien en casa!!!', 'captura') 


Comon Functions:

function mail (to, subject, message, att)
  -- make sure these settings are correct
  local settings = {
    -- "from" field, only e-mail must be specified here
    from = '......',
    -- smtp username
    user = '.....',
    -- smtp password
    password = '......',
    -- smtp server
    server = 'smtp.gmail.com',
    -- smtp server port
    port = 465,
    -- enable tls, required for gmail smtp
    secure = 'tlsv1_2',
  }
  -- make sure these settings are correct
  local smtp = require('socket.smtp')
  
  local escape = function(v)
  return '<' .. tostring(v) .. '>'
end

  local from_name = '.......'
  if att then
    local mime = require('mime')
        local ltn12 = require('ltn12')
    -- generate attachements
    bodyAtt = handleAtt(att) --bodyAtt = handleAtt(att, 'start')
  else
    bodyAtt = {"",""}
  end
  
  if type(to) ~= 'table' then
    to = { to }
  end
  
  for index, email in ipairs(to) do
    to[ index ] = escape(email)
  end
    
  settings.source = smtp.message({
    headers = {
      from = from_name..escape(settings.from),
      to = table.concat(to, ', '),
      subject = subject,
    },
    body = {
        --preamble = "Hello Recipient, \r\n" .. "This is your e-mail with a picture attached.",
        {
          header = {
            ['Content-type'] = 'text/html; charset=utf-8',
          },
          body = mime.eol(0, message),
        },
        bodyAtt[1],bodyAtt[2], -- get attachements if exists (max 2 for now)  <---todo:make it dynamic
        --epilogue = "That's it folks! Smile"
    }
  })
  bodyAtt = nil
   
  -- fixup from field
  settings.from = escape(settings.from)
  settings.rcpt = to

  smtp.send(settings)
end


function handleAtt(att)
    if att == "captura" then
    local snapshot = 'CAMERAIP'--..math.random(0, 1000000000000)
    
    log (snapshot)
    
    local attachment = ltn12.source.chain( ltn12.source.string(snapshot), ltn12.filter.chain(mime.encode('base64'), mime.wrap()) )
    return 
      {
        {
          headers = {
            ['Content-type'] = 'image/jpeg; name="Captura.jpg"',
            ['Content-disposition'] = 'attachment; filename="Captura.jpg"',
            ['Content-transfer-encoding'] = 'BASE64',
          },
          body = attachment
        }
            }
  
end
end
  

Thanks!!!
Reply


Messages In This Thread
RE: email with attachement gives image size 0 - by DGrandes - 12.07.2018, 08:20

Forum Jump: