LogicMachine Forum
Sendgrid email problem with an old backup - Printable Version

+- LogicMachine 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: Sendgrid email problem with an old backup (/showthread.php?tid=5242)



Sendgrid email problem with an old backup - savaskorkmaz - 13.02.2024

Hi,

We have a 2023 firmware LM5LP2 . We were sending email via using sendgrid system. Then we restored an old backup to this LM. We changed email information from custom functions with our sendgrid information . Same LM, same network, same ip address, also LM is connected to internet but we can't send email with our sendgrid information. 

Then We made factory settings. We changed network settings like used to. we added our sendgrid information to same LM and we can send email with sendgrid. Then i just restored old backup one more time. Changed custom functions email informaition to sendgrid. Again we can't send email.

How can i use my old backup with new LM , new firmware and sendgrid email function ? Should i change something diffeernt then common function email settings ?

Regards,


RE: Sendgrid email problem with an old backup - admin - 13.02.2024

Point nr.4 here: https://forum.logicmachine.net/showthread.php?tid=2531


RE: Sendgrid email problem with an old backup - savaskorkmaz - 13.02.2024

Hi ,

I changed my event script like , you can find the results below
Event Script :
subject = 'E-mail test sendgrid'
message = 'Testing e-mail sendgrid'
mail('savask@itsona.com', subject, message)

data, err = require('ssl.https').request('https://google.com/')
log(data, err)

Results :


RE: Sendgrid email problem with an old backup - admin - 13.02.2024

No, you need to log what the mail function returns:
Code:
subject = 'E-mail test sendgrid' message = 'Testing e-mail sendgrid' res, err = mail('savask@itsona.com', subject, message) log(res, err)



RE: Sendgrid email problem with an old backup - savaskorkmaz - 13.02.2024

Ok here is the log :


* arg: 1
* nil
* arg: 2
* string: 550 MIME message is missing 'From' header


RE: Sendgrid email problem with an old backup - admin - 13.02.2024

Your mail() in Common functions is outdated. Replace it with this one and don't forget to change the settings table.
Code:
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



RE: Sendgrid email problem with an old backup - savaskorkmaz - 13.02.2024

It's done. Thank you