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 function
#1
Dear Daniel,

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

BR

Attached Files Thumbnail(s)
   
Reply
#2
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
Reply
#3
Hi,

and what should I do?

BR
Reply
#4
Use mail() from common functions. Edit parameters as needed.
Reply
#5
Sorry I can't understand.

I have restored AN011 Email functions.
Is that not right?
Reply
#6
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.
Reply
#7
I have already done this. Shod I remove from user ibraries the email.user?
Reply
#8
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
Reply
#9
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", "Παραβίαση Σπιτιού")
Reply
#10
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
Reply
#11
It was Google security issue.
It is working fine.

Thanks a lot Erwin!
Reply
#12
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)--------
Reply
#13
Maybe the mail server had blackisted the external IP of the network where LM resides. Have you tried sending emails from the same network?
Reply
#14
(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.
Reply
#15
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.
Reply
#16
Try sslv23 or sslv3
Reply
#17
(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

Reply
#18
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.
Reply
#19
sometimes I solved with

secure = 'tlsv1_2'
KNX Advanced Partner + Tutor
Reply
#20
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.
Reply


Forum Jump: