温馨提示×

Linux的sendmail命令怎么使用

小亿
193
2023-07-13 12:28:52
栏目: 智能运维

sendmail是一个用于发送邮件的命令行工具,常用于Linux系统。下面是sendmail命令的用法:

  1. 发送简单的文本邮件:
echo "This is the body of the email" | sendmail recipient@example.com

这个命令会将文本"This is the body of the email"作为邮件正文发送给recipient@example.com。

  1. 发送带有主题和发件人的邮件:
echo "This is the body of the email" | sendmail -s "Subject of the email" -f sender@example.com recipient@example.com

这个命令会将文本"This is the body of the email"作为邮件正文发送给recipient@example.com,同时指定邮件主题为"Subject of the email",发件人为sender@example.com。

  1. 发送带有附件的邮件:
(echo "This is the body of the email"; uuencode attachment.txt attachment.txt) | sendmail -s "Subject of the email" -f sender@example.com recipient@example.com

这个命令会将文本"This is the body of the email"作为邮件正文发送给recipient@example.com,同时指定邮件主题为"Subject of the email",发件人为sender@example.com,并且附加了名为attachment.txt的附件。

  1. 从文件中读取邮件内容:
sendmail -t < email.txt

这个命令会从名为email.txt的文件中读取邮件内容,并发送。

以上是sendmail命令的一些常用用法,你可以根据自己的需求进行调整和扩展。

0