nginx配置

lua_package_path "/usr/local/openresty/lualib/resty/smtp/?.lua;;";
lua_need_request_body on;
location ^~ /alarm/mail {
  resolver 202.106.0.20 valid=3600s;
  content_by_lua_file /path/to/send_mail.lua;
}

其中resolver后为dns服务器ip;

 

lua代码

local smtp = require "resty.smtp"
local mime = require "resty.smtp.mime"
local mesgt = {
    headers= {
        subject= mime.ew("$subject", nil, { charset= "utf-8" }),
        ["content-transfer-encoding"]= "BASE64", ["content-type"]= "text/html; charset='utf-8'",
    },
    body= mime.b64("$body")
}
local ret, err = smtp.send {
    from= "$from_email",
    rcpt= { "$to_email" },
    user= "$from_email",
    password= "$password",
    server= "$smtp_server",
    port= 25,
    timeout= 30000,
    ssl= {enable= false, verify_cert= false},
    domain= "$domain",
    source= smtp.message(mesgt),
}

 

参考:

https://github.com/duhoobo/lua-resty-smtp

相关文章:

  • 2021-10-12
  • 2021-12-28
  • 2021-12-14
  • 2021-08-02
  • 2021-12-01
  • 2022-03-08
  • 2021-12-30
  • 2021-07-06
猜你喜欢
  • 2021-11-05
  • 2021-06-06
  • 2021-09-01
  • 2021-12-20
  • 2022-02-28
  • 2021-09-26
  • 2021-07-18
相关资源
相似解决方案