Posts: 24
Threads: 7
Joined: May 2018
Reputation:
0
Good morning:
I can't send the emails from Logic Machine
In Scriptin, common funtions I have configured this way:
-- 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 = 'logicmahine@gmail.com',
-- smtp username
user = 'logicmahine@gmail.com',
-- smtp password
password = 'logicmachine1234',
-- smtp server
server = 'smtp.gmail.com',
-- smtp server port
port = 465,
-- enable ssl, required for gmail smtp
secure = 'sslv23',
}
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
Then I created an event through a virtual object called Test
value = event.getvalue()
if value == true then
mail('myemail@gmail.com','Alarma Prueba','Alarma Prueba')
else
mail('myemail@gmail.com','No Alarma Prueba','Alarma Prueba Desactiva')
end
But when the value of the event is "1" I don't receive any email
I have verified that the mail I created for LM is operational
Can you help me someone please?
BR
Josema
Posts: 1759
Threads: 6
Joined: Jul 2015
Reputation:
115
Hi,
Did you set the default GW and DNS correctly in the network settings?
Otherwise log the err in the mail function, this will give you some direction what goes wrong..
BR,
Erwin
Posts: 303
Threads: 87
Joined: May 2017
Reputation:
2
Code: -- 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 = 'example@gmail.com',
-- smtp username
user = 'example@gmail.com',
-- smtp password
password = 'mypassword',
-- smtp server
server = 'smtp.gmail.com',
-- smtp server port
port = 465,
-- enable tls, 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
-- fixup from field
local from = '<' .. tostring(settings.from) .. '>'
-- message headers and body
settings.source = smtp.message({
headers = {
to = table.concat(to, ', '),
subject = subject,
['From'] = from,
['Content-type'] = 'text/html; charset=utf-8',
},
body = message
})
settings.from = from
settings.rcpt = to
return smtp.send(settings)
end
This works great for me, with gmail. Could the error be the secure line i see that you use ssl
Posts: 24
Threads: 7
Joined: May 2018
Reputation:
0
16.11.2019, 21:23
(This post was last modified: 16.11.2019, 21:28 by josemabera.)
When I send a "true" through the virtual object, the following message appears in Error log:
User script:5: attempt to call global 'Log' (a nil value)
stack traceback:
User script:5: in main chunk
I don't know what it means
(16.11.2019, 11:54)Erwin van der Zwart Wrote: Hi,
Did you set the default GW and DNS correctly in the network settings?
Otherwise log the err in the mail function, this will give you some direction what goes wrong..
BR,
Erwin Thanks for your response Erwin , but what is the GW? ( Excuse my ignorance), in the LM in System Confyg, network I don't see where to configure the DNS ..
BR ,
Josema
Posts: 1759
Threads: 6
Joined: Jul 2015
Reputation:
115
Hi,
Under System -> Network -> Interfaces you can double click on the NIC eth0 and there you can set the DNS and default GW (Gateway). When this is not set your controller can’t communicate with the internet and makes it impossible to send mail to Gmail (:
BR,
Erwin
Posts: 24
Threads: 7
Joined: May 2018
Reputation:
0
17.11.2019, 11:30
(This post was last modified: 17.11.2019, 11:41 by josemabera.)
(16.11.2019, 22:01)Erwin van der Zwart Wrote: Hi,
Under System -> Network -> Interfaces you can double click on the NIC eth0 and there you can set the DNS and default GW (Gateway). When this is not set your controller can’t communicate with the internet and makes it impossible to send mail to Gmail (:
BR,
Erwin Hi Erwin
If is configured
DNS1= 8.8.8.8
DNS2 = 8.8.4.4
and the GW also is configured
Even so it doesn't work, I can't attach Image captures to show you
(16.11.2019, 20:32)Tokatubs Wrote: Code: -- 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 = 'example@gmail.com',
-- smtp username
user = 'example@gmail.com',
-- smtp password
password = 'mypassword',
-- smtp server
server = 'smtp.gmail.com',
-- smtp server port
port = 465,
-- enable tls, 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
-- fixup from field
local from = '<' .. tostring(settings.from) .. '>'
-- message headers and body
settings.source = smtp.message({
headers = {
to = table.concat(to, ', '),
subject = subject,
['From'] = from,
['Content-type'] = 'text/html; charset=utf-8',
},
body = message
})
settings.from = from
settings.rcpt = to
return smtp.send(settings)
end
This works great for me, with gmail. Could the error be the secure line i see that you use ssl Hi Tokatubs
I don't understand exactly what you tell me about the ssl Secure Line, how can I modify it to test what you tell me?
BR
Josema
Posts: 303
Threads: 87
Joined: May 2017
Reputation:
2
If your problem is sending email with gmail, i think that you are using an old script.
Take a look at line 16 it says tlsv1_2 and not Ssl as is in your script on the top.
I had some problem some time ago, and Admin dropped the script i linked, and then i got the Gmail working. Could be worth a try..
Posts: 24
Threads: 7
Joined: May 2018
Reputation:
0
(17.11.2019, 22:10)Tokatubs Wrote: If your problem is sending email with gmail, i think that you are using an old script.
Take a look at line 16 it says tlsv1_2 and not Ssl as is in your script on the top.
I had some problem some time ago, and Admin dropped the script i linked, and then i got the Gmail working. Could be worth a try.. Thank you very much for your response: I have changed line 16 from ssl to tlsv1_2 but I still do not receive the LM e-mails, I have tested it in the 3 LMs that I have installed in different projects, but I do not receive the e-mails, I miss it is that in one of the projects I did receive them with the common function of sending an e-mail with ssl, but now I do not receive them
any other suggestions?
Posts: 7720
Threads: 42
Joined: Jun 2015
Reputation:
446
log the result of mail function:
Code: res, err = mail(...)
log(res, err)
Posts: 24
Threads: 7
Joined: May 2018
Reputation:
0
(18.11.2019, 07:31)admin Wrote: log the result of mail function:
Code: res, err = mail(...)
log(res, err)
Good morning Admin, thank you very much for the answer, this is the answer to the log:
* arg: 1
* nil
* arg: 2
* string: 535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8 https://support.google.com/mail/?p=BadCredentials j3sm21727187wrs.70 - gsmtp
As I have a moment I will check the username and password again, but have I done it before????
BR,
Josema
Posts: 4572
Threads: 23
Joined: Aug 2017
Reputation:
206
------------------------------
Ctrl+F5
Posts: 24
Threads: 7
Joined: May 2018
Reputation:
0
19.11.2019, 05:43
(This post was last modified: 19.11.2019, 05:47 by josemabera.)
(18.11.2019, 09:16)Daniel. Wrote: It is probably this
https://devanswers.co/allow-less-secure-...l-account/ Good morning Daniel
Thank you very much for the information, I have only allowed access to unsafe apps in the Gmail account and I already receive the test emails, in two of the three LMs that I have installed the third party does not send them to me, I will check the account carefully something must not be right
BR,
Josema
(17.11.2019, 22:10)Tokatubs Wrote: If your problem is sending email with gmail, i think that you are using an old script.
Take a look at line 16 it says tlsv1_2 and not Ssl as is in your script on the top.
I had some problem some time ago, and Admin dropped the script i linked, and then i got the Gmail working. Could be worth a try.. Hi Tokabus
after several tests
the script works with ssl, the problem was with the gmail account that I solved by enabling access to unsafe Apps on the account
Thank you very much for your help
BR,
Josema
Posts: 14
Threads: 2
Joined: Jul 2020
Reputation:
0
Hello,
I trying to use the same script as above, but when I enter my new google account made for testing with LM, and enter "less secure app access" https://devanswers.co/allow-less-secure-...l-account/ it says that "this setting is not supported by google anymore".
Does that mean that I cant use a @gmail to send e-mails from LM anymore?
Posts: 4572
Threads: 23
Joined: Aug 2017
Reputation:
206
------------------------------
Ctrl+F5
Posts: 14
Threads: 2
Joined: Jul 2020
Reputation:
0
|