本文介绍了如何使用HP-UX shell脚本将简单文本文件作为附件发送?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用HP-UX中的shell脚本发送带有文本文件作为附件的电子邮件;我没有安装mutt。
I need to send an email with a text file as attachment using shell script in HP-UX; I don't have mutt installed.
我正在使用以下命令,但它发送电子邮件正文中的文件内容,我希望它作为附件。
I am using following command but it sends the file content in body of email, I want it as an attachment.
mailx -s "Report" [email protected] < file.txt
推荐答案
我写了这个 ksh
函数几年前
# usage: email_attachment to cc subject body attachment_filename
email_attachment() {
to="$1"
cc="$2"
subject="$3"
body="$4"
filename="${5:-''}"
boundary="_====_blah_====_$(date +%Y%m%d%H%M%S)_====_"
{
print -- "To: $to"
print -- "Cc: $cc"
print -- "Subject: $subject"
print -- "Content-Type: multipart/mixed; boundary=\"$boundary\""
print -- "Mime-Version: 1.0"
print -- ""
print -- "This is a multi-part message in MIME format."
print -- ""
print -- "--$boundary"
print -- "Content-Type: text/plain; charset=ISO-8859-1"
print -- ""
print -- "$body"
print -- ""
if [[ -n "$filename" && -f "$filename" && -r "$filename" ]]; then
print -- "--$boundary"
print -- "Content-Transfer-Encoding: base64"
print -- "Content-Type: application/octet-stream; name=$filename"
print -- "Content-Disposition: attachment; filename=$filename"
print -- ""
print -- "$(perl -MMIME::Base64 -e 'undef $/; open $fh, shift; print MIME::Base64::encode(<$fh>); close $fh; ' $filename)"
print -- ""
fi
print -- "--${boundary}--"
} | /usr/lib/sendmail -oi -t
}
这篇关于如何使用HP-UX shell脚本将简单文本文件作为附件发送?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!