mail
命令默认使用系统上的邮件传输代理(MTA)来发送邮件。你需要确保系统上已经配置了正确的 MTA,并且系统能够正常发送电子邮件。
另外,某些系统可能需要配置额外的参数(如 SMTP 服务器地址、端口号、身份验证等)。具体的配置和使用方法可能因系统而异,请根据实际情况进行调整。
最后,值得一提的是,Shell 的 mail
命令相对较简单,并不像 PowerShell 那样提供丰富的邮件发送功能。如果你需要更复杂的邮件操作,建议使用其他编程语言或脚本语言来完成。
最简单的发送邮件方式
echo "This is the body of the email" | mail -s "Test email" recipient@example.com
包含附件的邮件
echo "This is the body of the email" | mail -s "Test email with attachment" -a /path/to/attachment.txt recipient@example.com
从文件中读取邮件内容
mail -s "Test email" recipient@example.com < /path/to/email_body.txt