我需要通过mailx或邮件发送文件,但我发送它作为附件而不是在正文消息中.有什么方法可以做到吗?最终在solaris中是否还有其他可用于此类程序的工具?谢谢
Jef*_*eff 13
您可以使用-a这样将文件附加到mailx
echo "this is the body of the email" | mailx -s"Subject" -a attachment.jpg Someone@Domain.com
Run Code Online (Sandbox Code Playgroud)
只要您在与附件相同的目录中就可以正常工作.如果没有,你可以像``一样说明目录
samachPicsFolder/samachpic.jpg
Run Code Online (Sandbox Code Playgroud)
如果您mailx不支持该-a选项并且无法访问mutt,并且您不想将其uuencode作为 20 世纪 80 年代的后备方案,那么作为最后的手段,您可以自己拼凑一个小型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
Run Code Online (Sandbox Code Playgroud)
通往的路径sendmail通常取决于系统。尝试/usr/sbin/sendmail或/usr/lib/sendmail或...无数其他奇怪的地方,如果它不在你的PATH.
这又快又脏;为了正确遵守 MIME,您应该在必要时对主题进行 RFC2047 编码等,另请参阅代码注释中的注释。但对于一般以美国为中心的 7 位英语 cron 作业来说,它就足够了。