mirror of
https://github.com/dawidd6/action-send-mail.git
synced 2024-11-10 05:51:07 +07:00
34 lines
653 B
Ruby
Executable File
34 lines
653 B
Ruby
Executable File
#!/usr/bin/env ruby
|
|
# frozen_string_literal: true
|
|
|
|
require 'net/smtp'
|
|
|
|
# Inputs
|
|
address = ENV["INPUT_SERVER_ADDRESS"]
|
|
port = ENV["INPUT_SERVER_PORT"]
|
|
username = ENV["INPUT_USERNAME"]
|
|
password = ENV["INPUT_PASSWORD"]
|
|
subject = ENV["INPUT_SUBJECT"]
|
|
body = ENV["INPUT_BODY"]
|
|
to = ENV["INPUT_TO"]
|
|
from = ENV["INPUT_FROM"]
|
|
|
|
# Message
|
|
message = <<EOM
|
|
Subject: #{subject}
|
|
From: #{from} <#{username}>
|
|
|
|
#{body}
|
|
EOM
|
|
|
|
# Send
|
|
begin
|
|
smtp = Net::SMTP.new(address, port.to_i)
|
|
smtp.enable_tls
|
|
smtp.start(address, username, password, :login)
|
|
smtp.send_message(message, username, to.split(","))
|
|
rescue StandardError => e
|
|
puts "Error: #{e.message}"
|
|
exit 1
|
|
end
|