是否可以使用 rsyslog 附带的 ommail 模块通过本地 postfix 安装发送电子邮件。我使用 gmail 作为 smtp,而 ommail 不进行身份验证。在 rsyslog .conf 文件中使用类似以下内容可以吗?
module(load="ommail")
template (name="mailBody" type="string" string="RSYSLOG Alert\\r\\nmsg='%msg%'")
template (name="mailSubject" type="string" string="Emergency logged on %hostname%")
if $msg contains "hard disk fatal failure" then {
action(type="ommail" server="localhost" port="25"
mailfrom="rsyslog@localhost"
mailto="root"
subject.template="mailSubject"
action.execonlyonceeveryinterval="21600")
}
答案1
简短的回答 - 可以,但必须将 postfix 配置为使用外部邮件服务作为本地中继。如果上述配置不完整,postfix 可能无法使用外部服务作为中继将电子邮件发送到公共电子邮件。
- 我将跳过 Postfix 安装步骤(谷歌搜索任何postfix 安装方法)
- 使用您首选的邮件服务(例如 Gmail)配置 postfix。在此示例中,我将使用我所在地区的电子邮件服务 Inbox.LV。
#inbox: max 15 msg/h and 5msg/m
relayhost = [mail.inbox.lv]:465
#yahoo: cant get app password
#relayhost = [smtp.mail.yahoo.com]:465
# strict rate limiting
smtp_fallback_relay = [smtp.yandex.ru]:465
# Limit 15 emails per hour per email address
anvil_rate_time_unit = 3600s
smtpd_client_message_rate_limit = 15
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_type = cyrus
smtp_sasl_mechanism_filter = login
default_process_limit = 5
smtpd_client_connection_count_limit = 2
##enable to be able to send email using different external relays
smtp_sender_dependent_authentication = yes
sender_dependent_relayhost_maps = hash:/etc/postfix/sasl/sender_relay
smtp_sasl_password_maps = hash:/etc/postfix/sasl/pass_maps
- [main.cf included relays conf (run postconf on these files)][3]
- restart postfix service
- run to test that relay is working
`echo "This is a test email body." | mail -s "Subject" -a "From: [email protected]" [email protected]`
- 配置rsyslog发送电子邮件:
- 创建文件 /etc/rsyslog.d/email.conf 并在编辑后重新启动 rsyslog。
module(load="ommail")
template (name="mailBody" type="string" string="%timegenerated% %msg%")
template (name="mailSubject" type="string" string="LTE problem <%syslogtag%>")
action(type="ommail" server="127.0.0.1" port="25"
mailfrom="[email protected]"
mailto=["[email protected]"]
subject.template="mailSubject"
body.enable="on"
template="mailBody"
queue.type="FixedArray"
queue.filename="mailqueue"
queue.saveOnShutdown="on"
action.execOnlyOnceEveryInterval="60"
action.resumeRetryCount="-1"
action.reportSuspension="on"
action.reportSuspensionContinuation="on"
action.errorfile="/var/spool/rsyslog/ommailerror.log"
action.resumeInterval="5"
action.resumeIntervalMax="300"
)
请注意,ommail 的正文模板使用其他动作属性“template”和“body.enable”。
Linux Armbian 21.05.6 Focal
rsyslog swVersion="8.2001.0"
来自 mail.log 的示例 o/p:
Jan 16 15:42:44 orangepi3 postfix/pickup[310061]: B1E3D63CA9: uid=1000 from=<[email protected]>
Jan 16 15:42:44 orangepi3 postfix/cleanup[310871]: B1E3D63CA9: message-id=<[email protected]>
Jan 16 15:42:44 orangepi3 postfix/qmgr[266048]: B1E3D63CA9: from=<[email protected]>, size=352, nrcpt=1 (queue active)
Jan 16 15:42:48 orangepi3 postfix/smtp[310874]: B1E3D63CA9: to=<[email protected]>, relay=mail.inbox.lv[194.19.227.101]:465, delay=3.8, delays=0.03/0.05/3.5/0.24, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 4927F3E60F52)
Jan 16 15:42:48 orangepi3 postfix/qmgr[266048]: B1E3D63CA9: removed