Skip to content

Instantly share code, notes, and snippets.

@GUI
Created November 25, 2018 15:45
Show Gist options
  • Save GUI/4ec6e695b400d8128b5708c2acf4e8fa to your computer and use it in GitHub Desktop.
Save GUI/4ec6e695b400d8128b5708c2acf4e8fa to your computer and use it in GitHub Desktop.
local mail = require "resty.mail"
local mailer, err = mail.new({
host = "smtp.gmail.com",
port = 587,
starttls = true,
username = "YOUR.USERNAME@gmail.com",
password = "YOUR.PASSWORD",
})
if err then
ngx.log(ngx.ERR, "mail.new error: ", err)
return
end
local ok, err = mailer:send({
from = "Master Splinter <splinter@example.com>",
to = { "michelangelo@example.com" },
cc = { "leo@example.com", "Raphael <raph@example.com>", "donatello@example.com" },
subject = "Pizza is here!",
text = "There's pizza in the sewer.",
html = "<h1>There's pizza in the sewer.</h1>",
attachments = {
{
filename = "toppings.txt",
content_type = "text/plain",
content = "1. Cheese\n2. Pepperoni",
},
},
})
if err then
ngx.log(ngx.ERR, "mailer:send error: ", err)
return
end
print("mailer:send success: ", ok)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment