mirror of
https://github.com/dawidd6/action-send-mail.git
synced 2025-07-07 23:50:31 +07:00
Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
f16ced8d0e | |||
b4d21e7654 | |||
8fee2012a2 | |||
df3751004c | |||
2f26726c4f |
4
.github/workflows/test.yml
vendored
4
.github/workflows/test.yml
vendored
@ -11,7 +11,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
body:
|
body:
|
||||||
- README.md
|
- file://README.md
|
||||||
- Test of action completed successfully!
|
- Test of action completed successfully!
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
@ -25,5 +25,5 @@ jobs:
|
|||||||
password: ${{secrets.PASSWORD}}
|
password: ${{secrets.PASSWORD}}
|
||||||
subject: ${{github.repository}}
|
subject: ${{github.repository}}
|
||||||
body: ${{matrix.body}}
|
body: ${{matrix.body}}
|
||||||
to: ${{secrets.USERNAME}}
|
to: ${{github.event.pusher.email}},${{secrets.USERNAME}}
|
||||||
from: github-actions
|
from: github-actions
|
3
LICENSE
3
LICENSE
@ -1,7 +1,6 @@
|
|||||||
|
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2018 GitHub, Inc. and contributors
|
Copyright (c) 2020 Dawid Dziurla
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -13,10 +13,12 @@ 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
|
# Literal body:
|
||||||
body: Build job of ${{github.repository}} completed successfully!
|
body: Build job of ${{github.repository}} completed successfully!
|
||||||
# Read file contents as body:
|
# Read file contents as body:
|
||||||
body: README.md
|
body: file://README.md
|
||||||
to: obiwan@tatooine.com,yoda@dagobah.com
|
to: obiwan@tatooine.com,yoda@dagobah.com
|
||||||
from: Luke Skywalker
|
from: Luke Skywalker
|
||||||
|
# Optional content type:
|
||||||
|
content_type: text/html
|
||||||
```
|
```
|
||||||
|
@ -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
|
||||||
|
18
main.rb
18
main.rb
@ -4,20 +4,28 @@
|
|||||||
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
|
||||||
body = File.exist?(body) ? File.read(body) : body
|
prefix = 'file://'
|
||||||
|
body = if body.start_with?(prefix)
|
||||||
|
path = body.delete_prefix(prefix)
|
||||||
|
File.read(path)
|
||||||
|
else
|
||||||
|
body
|
||||||
|
end
|
||||||
|
|
||||||
# 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}>
|
||||||
|
|
||||||
@ -26,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}"
|
||||||
|
Reference in New Issue
Block a user