mirror of
https://github.com/dawidd6/action-send-mail.git
synced 2025-07-05 22:53:15 +07:00
Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
2f26726c4f | |||
ae69498bf4 | |||
f50066a2fe | |||
445b6879ac | |||
6e749a80b9 |
7
.github/workflows/test.yml
vendored
7
.github/workflows/test.yml
vendored
@ -8,6 +8,11 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
main:
|
main:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
body:
|
||||||
|
- file://README.md
|
||||||
|
- Test of action completed successfully!
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v1
|
uses: actions/checkout@v1
|
||||||
@ -19,6 +24,6 @@ jobs:
|
|||||||
username: ${{secrets.USERNAME}}
|
username: ${{secrets.USERNAME}}
|
||||||
password: ${{secrets.PASSWORD}}
|
password: ${{secrets.PASSWORD}}
|
||||||
subject: ${{github.repository}}
|
subject: ${{github.repository}}
|
||||||
body: Test of action completed successfully!
|
body: ${{matrix.body}}
|
||||||
to: ${{secrets.USERNAME}}
|
to: ${{secrets.USERNAME}}
|
||||||
from: github-actions
|
from: github-actions
|
@ -1,5 +1,5 @@
|
|||||||
FROM ruby:2.6-alpine
|
FROM ruby:2.6-alpine
|
||||||
|
|
||||||
COPY entrypoint.rb /
|
COPY *.rb /
|
||||||
|
|
||||||
ENTRYPOINT ["/entrypoint.rb"]
|
ENTRYPOINT ["/main.rb"]
|
||||||
|
@ -13,7 +13,10 @@ An action that simply sends a mail to multiple recipients.
|
|||||||
username: ${{secrets.MAIL_USERNAME}}
|
username: ${{secrets.MAIL_USERNAME}}
|
||||||
password: ${{secrets.MAIL_PASSWORD}}
|
password: ${{secrets.MAIL_PASSWORD}}
|
||||||
subject: Github Actions job result
|
subject: Github Actions job result
|
||||||
|
# Literal body:
|
||||||
body: Build job of ${{github.repository}} completed successfully!
|
body: Build job of ${{github.repository}} completed successfully!
|
||||||
|
# Read file contents as body:
|
||||||
|
body: file://README.md
|
||||||
to: obiwan@tatooine.com,yoda@dagobah.com
|
to: obiwan@tatooine.com,yoda@dagobah.com
|
||||||
from: Luke Skywalker
|
from: Luke Skywalker
|
||||||
```
|
```
|
||||||
|
@ -21,7 +21,7 @@ inputs:
|
|||||||
description: Subject of mail message
|
description: Subject of mail message
|
||||||
required: true
|
required: true
|
||||||
body:
|
body:
|
||||||
description: Body of mail message
|
description: Body of mail message (might be a filename to read from)
|
||||||
required: true
|
required: true
|
||||||
to:
|
to:
|
||||||
description: Recipients mail addresses (separated with comma)
|
description: Recipients mail addresses (separated with comma)
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
#!/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
|
|
42
main.rb
Executable file
42
main.rb
Executable file
@ -0,0 +1,42 @@
|
|||||||
|
#!/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']
|
||||||
|
|
||||||
|
# Body
|
||||||
|
prefix = 'file://'
|
||||||
|
body = if body.start_with?(prefix)
|
||||||
|
path = body.delete_prefix(prefix)
|
||||||
|
File.read(path)
|
||||||
|
else
|
||||||
|
body
|
||||||
|
end
|
||||||
|
|
||||||
|
# Message
|
||||||
|
message = <<~END_OF_MESSAGE
|
||||||
|
Subject: #{subject}
|
||||||
|
From: #{from} <#{username}>
|
||||||
|
|
||||||
|
#{body}
|
||||||
|
END_OF_MESSAGE
|
||||||
|
|
||||||
|
# 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
|
Reference in New Issue
Block a user