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.

Sendgrid email problem with an old backup
#1
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,
Reply
#2
Point nr.4 here: https://forum.logicmachine.net/showthread.php?tid=2531
Reply
#3
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 :
Reply
#4
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)
Reply
#5
Ok here is the log :


* arg: 1
* nil
* arg: 2
* string: 550 MIME message is missing 'From' header
Reply
#6
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
Reply
#7
It's done. Thank you
Reply


Forum Jump: