mirror of
https://github.com/dawidd6/action-send-mail.git
synced 2024-12-26 11:03:06 +07:00
new content_type input
allow to set Content-Type HTTP header to a desired value
This commit is contained in:
parent
df3751004c
commit
8fee2012a2
@ -29,6 +29,10 @@ inputs:
|
|||||||
from:
|
from:
|
||||||
description: Full name of mail sender
|
description: Full name of mail sender
|
||||||
required: true
|
required: true
|
||||||
|
content_type:
|
||||||
|
description: Content-Type HTTP header (MIME type)
|
||||||
|
required: false
|
||||||
|
default: text/plain
|
||||||
runs:
|
runs:
|
||||||
using: docker
|
using: docker
|
||||||
image: Dockerfile
|
image: Dockerfile
|
||||||
|
10
main.rb
10
main.rb
@ -4,14 +4,15 @@
|
|||||||
require 'net/smtp'
|
require 'net/smtp'
|
||||||
|
|
||||||
# Inputs
|
# Inputs
|
||||||
address = ENV['INPUT_SERVER_ADDRESS']
|
server_address = ENV['INPUT_SERVER_ADDRESS']
|
||||||
port = ENV['INPUT_SERVER_PORT']
|
server_port = ENV['INPUT_SERVER_PORT']
|
||||||
username = ENV['INPUT_USERNAME']
|
username = ENV['INPUT_USERNAME']
|
||||||
password = ENV['INPUT_PASSWORD']
|
password = ENV['INPUT_PASSWORD']
|
||||||
subject = ENV['INPUT_SUBJECT']
|
subject = ENV['INPUT_SUBJECT']
|
||||||
body = ENV['INPUT_BODY']
|
body = ENV['INPUT_BODY']
|
||||||
to = ENV['INPUT_TO']
|
to = ENV['INPUT_TO']
|
||||||
from = ENV['INPUT_FROM']
|
from = ENV['INPUT_FROM']
|
||||||
|
content_type = ENV['INPUT_CONTENT_TYPE'] || 'text/plain'
|
||||||
|
|
||||||
# Body
|
# Body
|
||||||
prefix = 'file://'
|
prefix = 'file://'
|
||||||
@ -24,6 +25,7 @@ body = if body.start_with?(prefix)
|
|||||||
|
|
||||||
# Message
|
# Message
|
||||||
message = <<~END_OF_MESSAGE
|
message = <<~END_OF_MESSAGE
|
||||||
|
Content-Type: #{content_type}; charset=utf-8
|
||||||
Subject: #{subject}
|
Subject: #{subject}
|
||||||
From: #{from} <#{username}>
|
From: #{from} <#{username}>
|
||||||
|
|
||||||
@ -32,9 +34,9 @@ END_OF_MESSAGE
|
|||||||
|
|
||||||
# Send
|
# Send
|
||||||
begin
|
begin
|
||||||
smtp = Net::SMTP.new(address, port.to_i)
|
smtp = Net::SMTP.new(server_address, server_port.to_i)
|
||||||
smtp.enable_tls
|
smtp.enable_tls
|
||||||
smtp.start(address, username, password, :login)
|
smtp.start(server_address, username, password, :login)
|
||||||
smtp.send_message(message, username, to.split(','))
|
smtp.send_message(message, username, to.split(','))
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
puts "Error: #{e.message}"
|
puts "Error: #{e.message}"
|
||||||
|
Loading…
Reference in New Issue
Block a user