有多种方法,从命令行发送邮件,我在这里分享几个选项。您可以使用任何给定的选项从Linux命令发送电子邮件
[root@howtoing ~]# cat /tmp/email.txt Subject: Terminal Email Send Email Content line 1 Email Content line 2Subject: 电子邮件标题。 现在,使用下面的命令发送电子邮件。
[root@howtoing ~]# sendmail user@example.com < /tmp/email.txt了解更多:安装和配置Sendmail在CentOS / RHEL
[root@howtoing ~]# mail -s "Test Subject" user@example.com < /dev/null-s 用于定义电子邮件的主题。 要使用附件发送电子邮件。
# mail -a /opt/backup.sql -s "Backup File" user@example.com < /dev/null-a 用于附件 此外,我们可以添加逗号分隔的电子邮件发送电子邮件给多个收件人。
# mail -s "Test Email" user@example.com,user2@example.com < /dev/null
# mutt -s "Test Email" user@example.com < /dev/null发送电子邮件附件
# mutt -s "Test Email" -a /opt/backup.sql user@example.com < /dev/null
# ssmtp admin@example.com Subject: Test SSMTP Email Email send test using SSMTP via SMTP server. ^d了解更多:如何在Linux中安装ssmtp服务
# telnet localhost smtp Trying 127.0.0.1... Connected to localhost.localdomain (127.0.0.1). Escape character is '^]'. 220 fbreveal.com ESMTP Sendmail 8.13.8/8.13.8; Tue, 22 Oct 2013 05:05:59 -0400 HELO yahoo.com 250 howtoing.com Hello howtoing.com [127.0.0.1], pleased to meet you mail from: sender@howtoing.com 250 2.1.0 sender@howtoing.com... Sender ok rcpt to: myemail@ymail.com 250 2.1.5 myemail@ymail.com... Recipient ok data 354 Enter mail, end with "." on a line by itself Hey This is test email only Thanks . 250 2.0.0 r9M95xgc014513 Message accepted for delivery quit 221 2.0.0 fbreveal.com closing connection Connection closed by foreign host.感谢您使用这篇文章。我们将很快添加更多的途径。如果你知道上面没有列出的命令,可以回复此文章。
关注云架构公众号
Linux入门
QQ交流群:308781113