32 lines
822 B
Ruby
32 lines
822 B
Ruby
# Mailer module
|
|
module Mail
|
|
def send(to, subject, body)
|
|
from_email = "infinsweeper@syedm.dev"
|
|
from_name = "InfinSweeper"
|
|
to = Array(to).map { |addr| { email_address: { address: addr, name: "" } } }
|
|
|
|
payload = {
|
|
from: {
|
|
address: from_email,
|
|
name: from_name,
|
|
},
|
|
to: to,
|
|
subject: subject,
|
|
htmlbody: body,
|
|
}
|
|
|
|
uri = URI("https://api.zeptomail.com/v1.1/email")
|
|
req = Net::HTTP::Post.new(uri)
|
|
req["Authorization"] = "Zoho-enczapikey #{ENV_HASH["ZOHO_PASS"]}"
|
|
req["Content-Type"] = "application/json"
|
|
req.body = payload.to_json
|
|
|
|
http = Net::HTTP.new(uri.host, uri.port)
|
|
http.use_ssl = true
|
|
response = http.request(req)
|
|
|
|
return if response.is_a?(Net::HTTPSuccess)
|
|
Logman.imp "[ZeptoMail ERROR] #{response.body}"
|
|
end
|
|
end
|