Logic Machine Forum
Email function - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Email function (/showthread.php?tid=2437)

Pages: 1 2


Email function - XSPA2474KW - 25.01.2020

Dear Daniel,

regarding our previous discussion yesterday about email, please see the picture below from log tab.

BR


RE: Email function - Erwin van der Zwart - 25.01.2020

Hi,

The default e-mail function in common functions is ‘mail’ and not ‘email’

You probably don’t have a function called ‘email’ resulting in this error.

BR,

Erwin


RE: Email function - XSPA2474KW - 25.01.2020

Hi,

and what should I do?

BR


RE: Email function - admin - 25.01.2020

Use mail() from common functions. Edit parameters as needed.


RE: Email function - XSPA2474KW - 25.01.2020

Sorry I can't understand.

I have restored AN011 Email functions.
Is that not right?


RE: Email function - admin - 25.01.2020

Open Scripting tab, click Common functions button. Editor will open and there will be mail() function defined there. Edit parameters like username and password in function body. Save and then you can use mail() in other scripts.


RE: Email function - XSPA2474KW - 25.01.2020

I have already done this. Shod I remove from user ibraries the email.user?


RE: Email function - Erwin van der Zwart - 25.01.2020

If you have a user lib with a function “email” in it, you probably missing “require('user.email')” at the start of your event script.

BR,

Erwin


RE: Email function - XSPA2474KW - 25.01.2020

I have the scripts below. Please tell me what to do.

Email function in user libraries

function Email(to, subject, message)
-- make sure these settings are correct

---------------BEGINNING OF USER EDITABLE AREA-------------------
local settings = {
-- "from" field, only e-mail must be specified here
from = 'christ.spagakas@gmail.com',
-- smtp username
user = 'christ.spagakas@gmail.com',
-- smtp password
password = '..............',
-- smtp server
server = 'smtp.gmail.com',
-- smtp server port
port = 465,
-- enable ssl, required for gmail smtp

secure = 'tlsv1_2',
}
-------------------END OF USER EDITABLE AREA---------------------

local smtp = require('socket.smtp')
local escape = function(v)
return '<' .. tostring(v) .. '>'
end

-- message headers and body
settings.source = smtp.message({
headers = {
to = escape(to),
subject = subject,
},
body = message
})

-- fixup from field
settings.from = escape(settings.from)
settings.rcpt = { escape(to) }

return smtp.send(settings)
end



This in common functions

-- user function library

-- send an e-mail,
--function mail(to, subject, message)
-- make sure these settings are correct
--local settings = {
-- "from" field, only e-mail must be specified here
-- from = 'christ.spagakas@gmail.com',
-- smtp username
-- user = 'christ.spagakas@gmail.com',
-- smtp password
-- password = '.....................',
-- smtp server
-- server = 'smtp.gmail.com',
-- smtp server port
-- port = 465,
-- enable ssl, required for gmail smtp
-- secure = 'sslv23',
--}

--local smtp = require('socket.smtp')
--local escape = function(v)
-- return '<' .. tostring(v) .. '>'
--end

-- message headers and body
--settings.source = smtp.message({
--headers = {
--to = escape(to),
--subject = subject,
--},
--body = message
--})

-- fixup from field
--settings.from = escape(settings.from)
--settings.rcpt = { escape(to) }

--return smtp.send(settings)
--end


and the script below for event

mail("christ.spagakas@gmail.com", "Alarm", "Παραβίαση Σπιτιού")
mail("v.matziri@gmail.com", "Alarm", "Παραβίαση Σπιτιού")

or
email("christ.spagakas@gmail.com", "Alarm", "Παραβίαση Σπιτιού")
email("v.matziri@gmail.com", "Alarm", "Παραβίαση Σπιτιού")


RE: Email function - Erwin van der Zwart - 25.01.2020

Hi,

You can call any function from common functions without loading the lib, so mail() should work when adding correct password and username. You probably need to enable “less secure apps” in your gmail account.

When calling a function from a user lib you need to load it first by require("user.yourlibname").

Right now you are calling the function ”email” but without loading it with require() and your function is Email() with a capital E and you are calling email() with a lower case e, script is case sensitive so this is also a reason why it does not work.

Why are you using the user lib for Email in the first place? I would use / adjust the one in common functions..

BR,

Erwin


RE: Email function - XSPA2474KW - 25.01.2020

It was Google security issue.
It is working fine.

Thanks a lot Erwin!


RE: Email function - Domoticatorino - 06.06.2020

Hi,
I take the opportunity of this thread to ask what does it mean the following when system try to send mails.

string: 421 4.4.5 Directory harvest attack detected

SMTP server is not gmail and it works fine in other system. But I am trying to send mail to a gmail receiver. Here below my script. I cannot find out a solution. Thanks.

-- send an e-mail,
function mail(to, subject, message)
-- make sure these settings are correct
local settings = {
-- "from" field, only e-mail must be specified here
from = 'xxxxx',
-- smtp username
user = 'xxxx',
-- smtp password
password = 'xxxx',
-- smtp server
server = 'xxx',
-- smtp server port
port = 25,
-- enable ssl, required for gmail smtp
-- secure = 'tlsv1_2',

}

local smtp = require('socket.smtp')

if type(to) ~= 'table' then
to = { to }
end

for index, email in ipairs(to) do
to[ index ] = '<' .. tostring(email) .. '>'
end

-- message headers and body
settings.source = smtp.message({
headers = {
to = table.concat(to, ', '),
subject = subject,
['Content-type'] = 'text/html; charset=utf-8',
},
body = message
})

-- fixup from field
settings.from = '<' .. tostring(settings.from) .. '>'
settings.rcpt = to

return smtp.send(settings)
end
res, err = mail(...)
log(res, err)--------


RE: Email function - admin - 07.06.2020

Maybe the mail server had blackisted the external IP of the network where LM resides. Have you tried sending emails from the same network?


RE: Email function - Domoticatorino - 07.06.2020

(07.06.2020, 07:26)admin Wrote: Maybe the mail server had blackisted the external IP of the network where LM resides. Have you tried sending emails from the same network?

Lm is not in my same network but it is connect in VPN. I am testing mail and sender and receiver are the same. I try to test in a different way.

Strange thing is that in the meantine I am testing the mail service on with another device in Lua (MPM by Schneider) and there is not any problem and it is directy connected to my network.


RE: Email function - Domoticatorino - 08.06.2020

I have spoken with my SMTP mail provider and they told me that port number is 465 with ssl protocol SSL v. 3.

But when I write in the script < secure = 'SSLv3' > I received the following log info:

invalid protocol (SSLv3).

What do you suggest?

Thanks.


RE: Email function - admin - 08.06.2020

Try sslv23 or sslv3


RE: Email function - Domoticatorino - 08.06.2020

(08.06.2020, 08:11)admin Wrote: Try sslv23 or sslv3

With sslv3 log is: string: invalid protocol (sslv3)

With sslv23 log is: string: 550 5.1.1 Mailbox <user.mail> does not exist




RE: Email function - admin - 08.06.2020

X.1.1 Bad destination mailbox address
The mailbox specified in the address does not exist. For Internet mail names, this means the address portion to the left of the "@" sign is invalid. This code is only useful for permanent failures.

Check that "to" parameter is correct in your scripts.


RE: Email function - toujour - 13.06.2020

sometimes I solved with

secure = 'tlsv1_2'


RE: Email function - Domoticatorino - 13.06.2020

Obviously function works fine. Further to many test it seems that the problem occurs when system sends mail to those providers which checks the
compliance RFC. Google, microsoft outlook 365 and Zimbra. When I send mail to those destination receiver does not receive the mail.
My smtp server gives me this error:

550-5.7.1 not RFC 5322 compliant:
550-5.7.1 'From' header is missing.
550-5.7.1 To reduce the amount of spam sent to Gmail, this message has been blocked. Please visit .....

I am trying to find out a solution.