发送电子邮件的简单脚本
headnode-notifier的Python项目详细描述
头节点通知程序
发送电子邮件的简单脚本。
用法示例
usage: headnode_notifier [address] [OPTION]
Simple script for email notifications. Uses gmail by default.
positional arguments:
Recipient address
optional arguments:
-h, --help show this help message and exit
-v, --version show program's version number and exit
--subject Message subject
--body Message body
--attach Attachment
--serv-addr Server address. Default <smtp.gmail.com>
--port Server's port. Default: <587>
--from-addr Account address.
--password-file Read password from exeternal file. Prevents hard-coding
password anywhere in this script. IMPORTANT! Password is
stored as plain text! Do NOT use with your personal
account!
假设您使用的是默认帐户,并且您的密码文件位于正确的位置
您可以指定邮件主题、内容并附加文件。
headnode_notifier.py recipient@domain.com --subject 'Important message' --body 'Hello there!' --attach ./some/file.zip
您也可以只发送空白消息,如果对其余部分使用默认值,则只有recipient@domain.com
是真正必需的。
如果您愿意,可以使用--serv-addr smpt.provider.com --port 42 --from-addr my.address@provider.com
配置处理
如果在cli中未指定选项,则会从headnode_notifier.config文件中读取该选项。它的目的是通过设置默认值来方便使用:
- 服务器地址。
- 港口。
- 邮箱地址
- /路径/到/密码文件
- 配置内容:
[server]
address = smtp.gmail.com
port = 587
[mailbox]
address =
password_file =
配置位置:$home
配置名称:
.headnode_notifier.config
密码处理
为了避免将密码存储在脚本中的任何位置,将从文件中读取密码。您可以使用--password-file /path/to/file
或在配置文件中指定路径。请记住,密码文件是纯文本的因此请谨慎使用该脚本。
使用gmail
如果使用gmail,请记住允许不太安全的应用程序连接。您可以在google account security page