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.

how to send an e-mail
#3
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
Reply


Messages In This Thread
how to send an e-mail - by josemabera - 16.11.2019, 11:05
RE: how to send an e-mail - by Tokatubs - 16.11.2019, 20:32
RE: how to send an e-mail - by josemabera - 16.11.2019, 21:23
RE: how to send an e-mail - by josemabera - 17.11.2019, 11:30
RE: how to send an e-mail - by Tokatubs - 17.11.2019, 22:10
RE: how to send an e-mail - by josemabera - 18.11.2019, 05:44
RE: how to send an e-mail - by admin - 18.11.2019, 07:31
RE: how to send an e-mail - by josemabera - 18.11.2019, 08:59
RE: how to send an e-mail - by Daniel - 18.11.2019, 09:16
RE: how to send an e-mail - by josemabera - 19.11.2019, 05:43
RE: how to send an e-mail - by AlexD - 06.09.2022, 11:05
RE: how to send an e-mail - by Daniel - 06.09.2022, 11:07
RE: how to send an e-mail - by AlexD - 06.09.2022, 12:00

Forum Jump: