Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Email 如何使用HP-UX shell脚本将简单文本文件作为附件发送?_Email_Shell_Unix_Mailx - Fatal编程技术网

Email 如何使用HP-UX shell脚本将简单文本文件作为附件发送?

Email 如何使用HP-UX shell脚本将简单文本文件作为附件发送?,email,shell,unix,mailx,Email,Shell,Unix,Mailx,我需要使用HP-UX中的shell脚本发送一封电子邮件,其中包含一个文本文件作为附件;我没有安装mutt 我使用以下命令,但它发送的电子邮件正文中的文件内容,我希望它作为附件 mailx -s "Report" name@example.com < file.txt mailx-s“报告”name@example.com

我需要使用HP-UX中的shell脚本发送一封电子邮件,其中包含一个文本文件作为附件;我没有安装mutt

我使用以下命令,但它发送的电子邮件正文中的文件内容,我希望它作为附件

mailx -s "Report" name@example.com < file.txt
mailx-s“报告”name@example.com是你的朋友

下面是一个经过测试的示例:

(uuencode .vimrc vimrc.txt; uuencode .zshrc zshrc.txt; echo Here are your attachments) | mailx -s 'Mail with attachments' email_address

几年前我写了这个
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
}
#用法:电子邮件_附件至cc主题正文附件_文件名
电邮(附件){
至=“$1”
cc=“$2”
主题=“3美元”
body=“$4”
filename=“${5:-''}”
boundary=“\u====\ uBlah\u===\ u$(日期+%Y%m%d%H%m%S)\u===\ u
{
打印--“到:$To”
打印--“抄送:$Cc”
打印--“主题:$Subject”
打印--“内容类型:多部分/混合;边界=\”$boundary“
打印--“Mime版本:1.0”
打印--“
打印--“这是MIME格式的多部分邮件。”
打印--“
打印--“--$boundary”
打印--“内容类型:文本/普通;字符集=ISO-8859-1”
打印--“
打印--“$body”
打印--“
如果[[-n“$filename”&&&f“$filename”&&r“$filename”];则
打印--“--$boundary”
打印--“内容传输编码:base64”
打印--“内容类型:应用程序/八位字节流;名称=$filename”
打印--“内容处置:附件;文件名=$filename”
打印--“
打印--“$(perl-MMIME::Base64-e'undf$/;打开$fh,shift;打印MIME::Base64::encode();关闭$fh;'$filename)”
打印--“
fi
打印--“${boundary}--”
}|/usr/lib/sendmail-oi-t
}

我遇到了同样的问题,uuencode的输出作为邮件正文的一部分而不是作为附加文件发送(至少在使用Outlook 2010查看发送的邮件时是这样)。我在这个帖子里找到了答案

添加-m会导致mailx在发送电子邮件时不添加MIME头行。OP的命令将更改为:


mailx-m-s“报告”name@example.com

几个月前我也遇到了同样的问题。
我需要的命令是
ux2dos

( cat message_content_file; ux2dos file.txt | uuencode file.txt file.txt ) | mailx -m -s "subject" -r mail@sender mail@recipient
我希望它能帮上忙

考虑到它不起作用,我尝试了uuencode abcd.txt abcd.txt | grep mailx-s“报告”name@example.com我收到的电子邮件在消息正文begin 644 abcd.txt M87-J:VIK87-J:V%S中包含以下内容:@IA@devs字体“不工作”是什么意思?哪个部分出现故障?数据已损坏,但仍然无法正常运行attachment@devs:您使用哪些邮件用户代理查看您的电子邮件?邮件是否都已损坏?@devs:您可以尝试其他客户端吗?比如OWA?不,我只在电视上扮演系统管理员。