使用 sendmail 发送文件

Tar*_*run 5 email scripts sendmail

我有一个使用 sendmail 函数发送电子邮件的 shell 脚本,代码如下

mailalert(){
sendmail -F Sender-Name -it <<END_MESSAGE
To: Recipient@example.com
Subject: Subject

Message
END_MESSAGE
}
Run Code Online (Sandbox Code Playgroud)

每当我调用这个函数时它就会被执行。现在我有一个文本文件,我想使用 sendmail 作为附件或作为它发送的电子邮件中的消息发送。我怎样才能做到这一点?我尝试了很多技巧,但似乎没有任何效果。请帮忙。

Tar*_*run 1

相当奇怪,但我使用了不同的方法,因为在使用uuencode它时开始执行但光标停留在位置,begin 644 /path/to/file所以我使用 cat 在消息正文中发送我的文件。

file=/path/to/file
mailalert(){
sendmail -F Sender-Name -it <<END_MESSAGE
To: Recipient@example.com
Subject: Subject

$(cat $file)
END_MESSAGE
}
Run Code Online (Sandbox Code Playgroud)

上面的代码运行得很好,但是当我在网络浏览器中看到该消息时,一切都很好。但是当我在 Thunderbird 中看到它时,它没有正确显示。这就像某种编码。

因此,我将保留这个问题,直到我暂时找不到正确的解决方案为止。