镜像自地址
https://github.com/betterfor/action-send-mail.git
已同步 2026-11-20 16:37:04 +00:00
update README.md and add README_ZH.md
这个提交包含在:
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@ -5,7 +5,7 @@ on:
|
||||
# Triggers the workflow on push or pull request events but only for the "main" branch
|
||||
push:
|
||||
branches: [ "main" ]
|
||||
paths-ignore: ["README.md"]
|
||||
paths-ignore: ["README.md", "README_ZH.md"]
|
||||
|
||||
# Allows you to run this workflow manually from the Actions tab
|
||||
workflow_dispatch:
|
||||
|
||||
60
README.md
60
README.md
@ -1,5 +1,59 @@
|
||||
# Container Action Template
|
||||
English | [简体中文](https://github.com/betterfor/action-send-mail/blob/main/README_ZH.md)
|
||||
|
||||
To get started, click the `Use this template` button on this repository [which will create a new repository based on this template](https://github.blog/2019-06-06-generate-new-repositories-with-repository-templates/).
|
||||
# Send Mail Github Action
|
||||
|
||||
For info on how to build your first Container action, see the [toolkit docs folder](https://github.com/actions/toolkit/blob/master/docs/container-action.md).
|
||||
An action that simply sends a mail to multiple recipients.
|
||||
|
||||
Some feature:
|
||||
|
||||
- Plain text body
|
||||
- HTML body
|
||||
- Multipart body (plain text + HTML)
|
||||
- Markdown to HTML
|
||||
- File attachments
|
||||
|
||||
## Usage
|
||||
|
||||
```yaml
|
||||
- name: Send mail
|
||||
uses: betterfor/action-sned-mail@main
|
||||
with:
|
||||
# Reqired mail server address
|
||||
server_address: smtp.qq.com
|
||||
# Optional Server port, default 25 (if server_port is 465 this connection use TLS)
|
||||
server_port: 465
|
||||
# Optional (recommended): mail server username
|
||||
username: ${{secrets.MAIL_USERNAME}}
|
||||
# Optional (recommended): mail server password
|
||||
password: ${{secrets.MAIL_PASSWORD}}
|
||||
# Required mail subject
|
||||
subject: Github Actions job results
|
||||
# Required recipients address
|
||||
to: alice@example.com, bob@example.com
|
||||
# Required sender full name (address can be skipped)
|
||||
from: alice # <alice@example.com>
|
||||
# Optional plain body
|
||||
body: Build job of ${{github.repository}} completed successfully!
|
||||
# Optional HTML body read from file
|
||||
html_body: file://README.md
|
||||
# Optional carbon copy recipients
|
||||
cc: a@example.com,b@example.com
|
||||
# Optional blind carbon copy recipients
|
||||
bcc: c@example.com,d@example.com
|
||||
# Optional recipient of the email response
|
||||
reply_to: luke@example.com
|
||||
# Optional Message ID this message is replying to
|
||||
in_reply_to: <random-luke@example.com>
|
||||
# Optional converting Markdown to HTML (set content_type to text/html too)
|
||||
convert_mardown: true
|
||||
# Optional attachments
|
||||
attachments: README.md
|
||||
# Optional priority: 'high', 'normal' (default) or 'low'
|
||||
priority: low
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Unauthenticated login (username/password field)
|
||||
|
||||
The parameters `username` and `password` are set as optional to support self-hosted runners access to on-premise infrastructrue. If you are accessing public email servers make sure you provide a username/password authentication through [Github Secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets) to make the email delivery secure.
|
||||
58
README_ZH.md
普通文件
58
README_ZH.md
普通文件
@ -0,0 +1,58 @@
|
||||
[English](https://github.com/betterfor/action-send-mail/blob/main/README.md) | 简体中文
|
||||
|
||||
# 发送邮件 Github Action
|
||||
|
||||
本 action 可以发送多个收件人。
|
||||
|
||||
一些特性:
|
||||
- 文本内容
|
||||
- HTML内容
|
||||
- 支持文本+HTML
|
||||
- Markdown转HTML
|
||||
- 附加文件
|
||||
|
||||
## 用法
|
||||
|
||||
```yaml
|
||||
- name: Send mail
|
||||
uses: betterfor/action-sned-mail@main
|
||||
with:
|
||||
# 必需,邮件服务器地址
|
||||
server_address: smtp.qq.com
|
||||
# 必需,邮件服务器端口,默认25 (如果端口为465,则会使用TLS连接)
|
||||
server_port: 465
|
||||
# 可选 (建议): 邮件服务器用户
|
||||
username: ${{secrets.MAIL_USERNAME}}
|
||||
# 可选 (建议): 邮件服务器密码
|
||||
password: ${{secrets.MAIL_PASSWORD}}
|
||||
# 必需,邮件主题
|
||||
subject: Github Actions job results
|
||||
# 必需,收件人地址
|
||||
to: alice@example.com, bob@example.com
|
||||
# 必需,发送人全名 (地址可以省略)
|
||||
from: alice # <alice@example.com>
|
||||
# 可选,文本内容
|
||||
body: Build job of ${{github.repository}} completed successfully!
|
||||
# 可选,HTML内容,可从文件读取
|
||||
html_body: file://README.md
|
||||
# 可选,抄送人
|
||||
cc: a@example.com,b@example.com
|
||||
# 可选,密抄送人
|
||||
bcc: c@example.com,d@example.com
|
||||
# 可选,邮件回执
|
||||
reply_to: luke@example.com
|
||||
# 可选,回执邮件消息ID
|
||||
in_reply_to: <random-luke@example.com>
|
||||
# 可选,markdown转HTML (会设置内容格式为text/html)
|
||||
convert_mardown: true
|
||||
# 可选,附件
|
||||
attachments: README.md
|
||||
# 可选,邮件优先级设置: 'high', 'normal' (default) or 'low'
|
||||
priority: low
|
||||
```
|
||||
|
||||
## 问题定位
|
||||
|
||||
### Unauthenticated login
|
||||
|
||||
参数`username`和`password`被设置为可选参数,以支持自我托管的运行者访问内部基础设施。如果你要访问公共电子邮件服务器,请确保你通过[Github Secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets)提供用户名/密码认证,以使电子邮件的发送安全。
|
||||
@ -10,8 +10,6 @@ inputs:
|
||||
server_port:
|
||||
description: SMTP server port
|
||||
default: "25"
|
||||
secure:
|
||||
description: Whether this connection use TLS (default is true if server_port is 465)
|
||||
username:
|
||||
description: Authenticate as this user to SMTP server
|
||||
password:
|
||||
@ -43,9 +41,6 @@ inputs:
|
||||
in_reply_to:
|
||||
description: The Message-ID this message is replying to
|
||||
required: false
|
||||
ignore_cert:
|
||||
description: Allow unsigned/invalid certificates
|
||||
required: false
|
||||
convert_markdown:
|
||||
description: Convert body from Markdown to HTML (set content_type input as text/html too)
|
||||
required: false
|
||||
|
||||
12
main.go
12
main.go
@ -18,7 +18,6 @@ import (
|
||||
func main() {
|
||||
mailHost := os.Getenv("INPUT_SERVER_ADDRESS")
|
||||
mailPort := convertInt(os.Getenv("INPUT_SERVER_PORT"))
|
||||
secure := convertBool(os.Getenv("INPUT_SECURE"))
|
||||
username := os.Getenv("INPUT_USERNAME")
|
||||
password := os.Getenv("INPUT_PASSWORD")
|
||||
subject := os.Getenv("INPUT_SUBJECT")
|
||||
@ -30,7 +29,6 @@ func main() {
|
||||
bcc := os.Getenv("INPUT_BCC")
|
||||
replyTo := os.Getenv("INPUT_REPLY_TO")
|
||||
inReplyTo := os.Getenv("INPUT_IN_REPLY_TO")
|
||||
//ignoreCert := viper.GetBool("ignore_cert")
|
||||
convertMarkdown := convertBool(os.Getenv("INPUT_CONVERT_MARKDOWN"))
|
||||
attachments := os.Getenv("INPUT_ATTACHMENTS")
|
||||
priority := os.Getenv("INPUT_PRIORITY")
|
||||
@ -61,10 +59,6 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
if !secure {
|
||||
secure = mailPort == 465
|
||||
}
|
||||
|
||||
if body != "" {
|
||||
m.SetBody("text/plain", getBody(body, false))
|
||||
}
|
||||
@ -72,8 +66,12 @@ func main() {
|
||||
m.SetBody("text/html", getBody(htmlBody, convertMarkdown))
|
||||
}
|
||||
|
||||
if mailPort == 0 {
|
||||
mailPort = 25
|
||||
}
|
||||
|
||||
dialer := gomail.NewDialer(mailHost, mailPort, username, password)
|
||||
if secure {
|
||||
if dialer.SSL {
|
||||
dialer.TLSConfig = &tls.Config{InsecureSkipVerify: true}
|
||||
}
|
||||
|
||||
|
||||
在新工单中引用
屏蔽一个用户