--***********************************************************-- --** Email image attachment created by Erwin van der Zwart **-- --***********************************************************-- --******************* Start of parameters *******************-- --***********************************************************-- --Gmail (smtp) username !IMPORTANT! user = 'YourGmailAddress@gmail.com' --Gmail (smtp) password !IMPORTANT! password = 'YourPassword' --Sender for e-mail from = '' alias_from = 'Erwin van der Zwart' --Recipient for e-mail to = '' alias_to = 'Erwin van der Zwart' --Subject for e-mail subject = 'Schneider Electric logo from website automaticly send by homeLYnk' --Attachment and filetype (set filetype as 'gif', 'png', 'bmp', 'jpg' or 'jpeg' according image source) image_type = 'gif' image_name_attachment = 'logo' source_image_url = 'http://www.schneider-electric.com/navigation/images/se_logo.gif' image_description = 'Logo from Schneider Electric' --Message on bottom of email (will only be showed when client don't understand attachment) epilogue = 'End of message' --***********************************************************-- --******************** End of parameters ********************-- --***********************************************************-- --********** DON'T CHANGE ANYTHING UNDER THIS LINE **********-- --***********************************************************-- --Get remote (from HTTP) image and put image file to HL (will be deleted when end of script) os.execute('wget -O /www/scada/vis/' .. image_name_attachment .. '.' .. image_type .. ' ' .. source_image_url .. '') --Create filename and location local fileName = '/www/scada/vis/' .. image_name_attachment .. '.' .. image_type --Create table to include mail settings local settings = { from = from, rcpt = to, user = user, password = password, server = 'smtp.gmail.com', port = 465, secure = 'sslv23', } --Load required modules to send email with attachment local smtp = require("socket.smtp") local mime = require("mime") local ltn12 = require("ltn12") --Create e-mail header settings.source = smtp.message{ headers = { from = '' .. alias_from .. ' ' .. from .. '', to = '' .. alias_to .. ' ' .. to .. '', subject = subject }, --Load attachment inside body body = { preamble = "", [1] = { headers = { ["content-type"] = 'image/' .. image_type .. '; name="' .. image_name_attachment .. '.' .. image_type .. '"', ["content-disposition"] = 'attachment; filename="' .. image_name_attachment .. '.' .. image_type .. '"', ["content-description"] = '' .. image_description .. '', ["content-transfer-encoding"] = "BASE64" }, body = ltn12.source.chain( ltn12.source.file(io.open(fileName, "rb")), ltn12.filter.chain( mime.encode("base64"), mime.wrap() ) ) }, epilogue = epilogue } } --Send the email r, e = smtp.send(settings) --Create alert when sending gives an error with error message if (e) then alert("Could not send email: ", e, "\n") end --Delete downloaded image file from HL os.remove(fileName)