邮件已发送但没有附件

时间:2018-10-12 11:24:14

标签: bash shell centos6

我正在使用以下Shell脚本发送带有附件的电子邮件。该脚本运行文件,但是当它由crontab运行时,附件文件不会与电子邮件一起发送。即已发送但没有附件的邮件。

我在centos 6.9下运行此脚本。

#!/bin/bash
DATE=`date -d "yesterday 13:00 " '+%Y-%m-%d'`
from="myemail@mydomain.com"
to="someone@domain.com"

subject="email title"
boundary="ZZ_/afg6432dfgkl.94531q"

body="email body"

declare -a attachments
attachments=( "action_details.txt" )

{   
printf '%s\n' "From: $from
To: $to
Subject: $subject
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary=\"$boundary\"

--${boundary}
Content-Type: text/plain; charset=\"US-ASCII\"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

$body
"

printf "

For More details,  Please check the attached file"

for file in "${attachments[@]}"; do

  [ ! -f "$file" ] && echo "Warning: attachment $file not found, skipping" >&2 && continue

  mimetype=$(get_mimetype "$file")

  printf '%s\n' "--${boundary}
Content-Type: $mimetype
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=\"$file\"
"

  base64 "$file"
  echo
done

# print last boundary with closing --
printf '%s\n' "--${boundary}--"

} | /usr/sbin/sendmail -t -oi   

0 个答案:

没有答案