我需要通过 mailx 或邮件发送文件,但我希望将其作为附件发送,而不是在正文消息中。有什么办法吗?最终,solaris 中是否有任何其他工具可用于诸如程序之类的工具?谢谢
问问题
46910 次
5 回答
13
您可以像这样使用 -a 将文件附加到 mailx
echo "this is the body of the email" | mailx -s"Subject" -a attachment.jpg Someone@Domain.com
只要您在与附件相同的目录中就可以正常工作。如果没有,您可以只声明目录,如`
samachPicsFolder/samachpic.jpg
于 2013-05-28T19:08:32.957 回答
4
如果您mailx
不支持该-a
选项并且您无权访问mutt
,并且您不想将其uuencode
作为 1980 年代的后备方案,那么作为最后的手段,您可以自己拼凑一个小型MIME包装器。
#!/bin/sh
# ... do some option processing here. The rest of the code
# assumes you have subject in $subject, file to be attached
# in $file, recipients in $recipients
boundary="${RANDOM}_${RANDOM}_${RANDOM}"
(
cat <<____HERE
Subject: $subject
To: $recipients
Mime-Version: 1.0
Content-type: multipart/related; boundary="$boundary"
--$boundary
Content-type: text/plain
Content-transfer-encoding: 7bit
____HERE
# Read message body from stdin
# Maybe apply quoted-printable encoding if you anticipate
# overlong lines and/or 8-bit character codes
# - then you should change the last body part header above to
# Content-Transfer-Encoding: quoted-printable
cat
cat <<____HERE
--$boundary
Content-type: application/octet-stream; name="$file"
Content-disposition: attachment; filename="$file"
Content-transfer-encoding: base64
____HERE
# If you don't have base64 you will have to reimplement that, too /-:
base64 "$file"
cat <<____HERE
--$boundary--
____HERE
) | sendmail -oi -t
路径sendmail
通常取决于系统。尝试/usr/sbin/sendmail
or /usr/lib/sendmail
or ... 如果它不在您的PATH
.
这又快又脏;为了正确地遵守 MIME,您应该在必要时对主题进行 RFC2047 编码等,另请参阅代码注释中的注释。但是对于您的以美国为中心的 7 位英语 cron 工作,它会做得很好。
于 2014-10-01T03:44:17.460 回答
1
关于mailx,你可以在这里找到一些灵感 http://www.shelldorado.com/articles/mailattachments.html
我建议你看看 mutt http://www.mutt.org/
于 2011-06-20T08:05:33.450 回答
1
尝试使用此命令以使用 Mailx 发送附件:
uuencode source_file encoded_filename |mailx -m -s "Subject" something@something.com
于 2017-03-14T19:33:33.303 回答
0
我建议使用mutt
它,它足够轻巧,可以快速安装在任何系统上。
于 2011-06-20T08:04:08.833 回答