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.

LM5 can't send an email
#1
Hi, 

I'm using this script in all of our projects to send a backup each month.
One of the LM5 can't send it anymore and  got this in the logs

* string: connection refused 
* nil
* string: Send Mail

NB: LM5 is connected to the ethernet.

What could be the issue?

Code:
--***************************************************************--
--*** For FW spaceLYnk 1.2.1 and FW homeLYnk 1.5.1 or higher ****--
--***************************************************************--
--** Email backup as attachment created by Erwin van der Zwart **--
--***************************************************************--
--********************* Start of parameters *********************--
--***************************************************************--

--Gmail (smtp) username !IMPORTANT!
user = 'xxxx'

--Gmail (smtp) password !IMPORTANT!
password = 'xxxx'

--Sender for e-mail
from = '<xxxx>'
alias_from = 'From me'

--Recipient for e-mail
to = '<xxxx>'
alias_to = 'To you'

--Subject for e-mail
subjectpart1 = 'Back-up file'
subjectpart2 = 'xxx'

--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 **********--
--***********************************************************--

--Create table to include mail settings
local settings = {
    from = from,
    rcpt = to,
    user = user,
    password = password,
    server = 'smtp.office365.com',
    port = 587,
    secure = 'tlsv1_2',
        starttls = true,
}

--Create attachment
src = 'backup-' .. os.date('%Y.%m.%d') .. '.tar.gz'
dst = '/home/ftp/' .. src

-- prepare files for backup
os.execute('sh /lib/genohm-scada/web/general/backup.sh')

-- create cleanup archive
os.execute('cd /lib/genohm-scada/storage && tar -c -z -f ' .. dst .. ' ./')

--Create subject
subject = subjectpart1 .. ": " .. src .. " " .. subjectpart2

--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"] = 'application/x-7z-compressed',
         ["content-disposition"] = 'attachment; filename="'..src..'"',
         ["content-description"] = '.. src ..',
         ["content-transfer-encoding"] = "BASE64",
      },
              
      body = ltn12.source.chain(
      ltn12.source.file(io.open(dst, "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
  log (e)
  log (r)
  alert("Could not send email: ", e, "\n")
end
log("Send Mail")

--Delete created backup file from tmp folder inside HL
os.execute('cd /lib/genohm-scada/storage && rm -rf user userlib.luas blockly.luas initscript.lua helpers.js genohm-scada.config filter*')
Reply
#2
Check this
https://forum.logicmachine.net/showthrea...1#pid26361
------------------------------
Ctrl+F5
Reply
#3
(14.04.2023, 09:19)Daniel Wrote: Check this
https://forum.logicmachine.net/showthrea...1#pid26361

The same script works on another LM5, and im not using gmail
Reply
#4
Is it the same gmial account?
------------------------------
Ctrl+F5
Reply
#5
(14.04.2023, 09:26)Daniel Wrote: Is it the same gmial account?

the same account yes
Reply
#6
Then it is ether typo in internet settings or some security stuff in gmail.
------------------------------
Ctrl+F5
Reply
#7
(14.04.2023, 09:27)Daniel Wrote: Then it is ether typo in internet settings or some security stuff in gmail.

it's not gmail, and i don't thing a typo because i copied the same script and test it and it works
Reply
#8
Try pinging SMTP server from LM.
Reply
#9
(14.04.2023, 09:29)admin Wrote: Try pinging SMTP server from LM.

PING smtp.office365.com (132.245.230.0): 56 data bytes
64 bytes from 132.245.230.0: seq=0 ttl=107 time=35.128 ms
64 bytes from 132.245.230.0: seq=1 ttl=107 time=41.218 ms
64 bytes from 132.245.230.0: seq=2 ttl=107 time=34.290 ms
64 bytes from 132.245.230.0: seq=3 ttl=107 time=33.080 ms

--- smtp.office365.com ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max = 33.080/35.929/41.218 m
Reply
#10
Is it the same firmware on working and not working LM?
------------------------------
Ctrl+F5
Reply
#11
(14.04.2023, 09:38)Daniel Wrote: Is it the same firmware on working and not working LM?

Yes
Reply
#12
Try running this script. If you still get connection refused error then contact Microsoft and ask why your connection is blocked.
Code:
sock = require('socket').tcp()
sock:settimeout(5)
res, err = sock:connect('smtp.office365.com', 587)
sock:close()
log(res, err)
Reply
#13
(14.04.2023, 11:37)admin Wrote: Try running this script. If you still get connection refused error then contact Microsoft and ask why your connection is blocked.
Code:
sock = require('socket').tcp()
sock:settimeout(5)
res, err = sock:connect('smtp.office365.com', 587)
sock:close()
log(res, err)
The problem is solved,  port 587 was blocked by the firewall
Reply


Forum Jump: