我正在尝试通过UNIX发送邮件,其中HTML正文和xlsx文件作为附件,但我无法使用邮件附加文件,任何人都可以共享一些示例代码吗?这是我尝试过的,为了简单起见,我必须将XLSX文件作为附件发送,我正在尝试使用CSV, Unix var文件是一个CSV文件,其中包含数据为abc,xyz @ gmail.com
echo $file
while read LINE
do
echo $LINE;
fund_provider_code=`echo $LINE | awk -F',' '{print$1}'`
len=`echo $fund_provider_code | awk '{print length}'`
length=`expr $len + 2`
email_list=`echo $LINE | cut -c $length-`
echo fund_code=$fund_provider_code
email=$email_list
(BOUNDARY='=== This is the boundary between parts of the message. ==='
ATTACHMENT="$attachment_file"
SUBJECT="$subject_text"
VERSION=1.0
print - 'To:' ${email_list}
print - 'Subject:' ${SUBJECT}
print - 'MIME-Version: 1.0'
print - 'Content-Type: MULTIPART/MIXED; '
print - 'Content-Type: TEXT/HTML; charset=US-ASCII'
print -
awk -v message1="${msg1}" ' BEGIN {
print "<html><body>"
print "<style>"
print "p.MsoNormal, li.MsoNormal, div.MsoNormal \{mso-style-parent:\"\"; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt;font-family:\"Arial\"; mso-fareast-font-family:\"MSMincho\";\}"
print "</style>"
print "<div class=Section1>"
print "<p class=MsoNormal style=\"mso-layout-grid-align:none;text-autospace:none\"><span style=\"font-size:12.0pt;font-family:'Arial';mso-bidi-font-family:'Arial'; color:Black\">Dear All,<o:p></o:p></span></p>"
print "</div></body></html>"
}' email_body.txt;
print -
print - "--${BOUNDARY}--"
print - 'ATTACH="/projects/dit/edw/EDW_OUTBOUND_FEEDS/bin/email.csv"'
print - 'Content-Type: TEXT/HTML, multipart/mixed, text/html, application/octet-stream ; name=email.csv'
print - "Content-Transfer-Encoding: base64"
print - 'Content-Disposition: attachment; filename=abc.csv'
uuencode "/projects/dit/edw/EDW_OUTBOUND_FEEDS/bin/email.csv" email.csv
print -
print - "--${BOUNDARY}--"
) | sendmail ${email_list}
done < "$file"
答案 0 :(得分:0)
看起来您要发送的文件名不一致。以下假设您要发送本地定义为:
的文件/projects/dit/edw/EDW_OUTBOUND_FEEDS/bin/email.csv
---但是,你没有正确定义它,所以我修改了作业:
ATTACH="/projects/dit/edw/EDW_OUTBOUND_FEEDS/bin/email.csv"
或者您想使用ATTACHMENT吗?我认为你必须清理这段代码。
ATTACHMENT="$attachment_file"
subject_text
未定义,或者它是我们在您的OP中没有看到的脚本的一部分?attachment_file
也未定义。我认为您应该在var:$ATTACH
echo $file
while read LINE
do
echo $LINE;
fund_provider_code=`echo $LINE | awk -F',' '{print$1}'`
len=`echo $fund_provider_code | awk '{print length}'`
length=`expr $len + 2`
email_list=`echo $LINE | cut -c $length-`
echo fund_code=$fund_provider_code
email=$email_list
(BOUNDARY='=== This is the boundary between parts of the message. ==='
ATTACHMENT="$attachment_file"
ATTACH="/projects/dit/edw/EDW_OUTBOUND_FEEDS/bin/email.csv"
SUBJECT="$subject_text"
VERSION=1.0
print - 'To:' ${email_list}
print - 'Subject:' ${SUBJECT}
print - 'MIME-Version: 1.0'
print - 'Content-Type: MULTIPART/MIXED; '
print - 'Content-Type: TEXT/HTML; charset=US-ASCII'
print -
awk -v message1="${msg1}" ' BEGIN {
print "<html><body>"
print "<style>"
print "p.MsoNormal, li.MsoNormal, div.MsoNormal \{mso-style-parent:\"\"; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt;font-family:\"Arial\"; mso-fareast-font-family:\"MSMincho\";\}"
print "</style>"
print "<div class=Section1>"
print "<p class=MsoNormal style=\"mso-layout-grid-align:none;text-autospace:none\"><span style=\"font-size:12.0pt;font-family:'Arial';mso-bidi-font-family:'Arial'; color:Black\">Dear All,<o:p></o:p></span></p>"
print "</div></body></html>"
}' email_body.txt;
print -
print - "--${BOUNDARY}--"
print - 'ATTACH="${ATTACH}"'
print - 'Content-Type: TEXT/HTML, multipart/mixed, text/html, application/octet-stream ; name="'$(basename ${ATTACH})'"'
print - "Content-Transfer-Encoding: base64"
print - 'Content-Disposition: attachment; filename="'$(basename ${ATTACH})'"'
uuencode $ATTACH $(basename ${ATTACH})
print - "--${BOUNDARY}--"
) | sendmail ${email_list}
done < "$file"
从examples我看到,如果你使用GNU uuencode
,你可能需要替换这行
uuencode $ATTACH $(basename $ATTACH)
通过
uuencode --base64 $ATTACH $(basename $ATTACH)