我试图使用SES API将附件作为csv文件的压缩内容发送。 csv文件大小接近3MB。我没有使用任何SDK,而是使用curl和API端点从bash shell中执行此操作。
代码有效,我也将zip作为邮箱中的附件。但是当我尝试下载时,它会告诉我文件损坏或损坏。
$ REPORTOUTFILE是csv文件
需要你的帮助,因为我无法找到解决方法。
CURRENT_PATH=$(pwd)
zip $CURRENT_PATH/message.zip $REPORTOUTFILE
ATTACHMENT_CONTENTS=`zcat $CURRENT_PATH/message.zip`
ATTACHMENT_TEXT="stuck_order_report_tmp_$DATE.zip"
ATTACHMENT_CONTENTS_ENCODED="$(echo "$ATTACHMENT_CONTENTS" | base64)"
VALUE="To:"$TO"
Subject: Email with Attachment
Content-Type: multipart/mixed;
boundary="a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a"
--a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a
Content-Type: multipart/alternative;
boundary="sub_a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a"
--sub_a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
--sub_a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
Hello ! This is the text content for the email body.
--sub_a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a--
--a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a
Content-Type: attachment/zip; name="$ATTACHMENT_TEXT"
Content-Description: "$ATTACHMENT_TEXT"
Content-Disposition: attachment;filename="$ATTACHMENT_TEXT";
Content-Transfer-Encoding: base64
$ATTACHMENT_CONTENTS_ENCODED
--a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a--"
MESSAGE="$(echo "$VALUE" | base64)"
echo "$MESSAGE" > $CURRENT_PATH/message_new.txt
message="RawMessage.Data=$MESSAGE"
echo "$message" > $CURRENT_PATH/message.txt
curl -v -X POST --trace "$CURRENT_PATH/trace.log" -H "Date: $date" -H "$auth_header" -H "$content_encoding" --data-binary "@$CURRENT_PATH/message.txt" --data-urlencode "$source" --data-urlencode "$action" "$endpoint"
答案 0 :(得分:1)
以下代码段最终有效
## AWS SES Invocation ##
CURRENT_PATH=$(pwd)
zip $CURRENT_PATH/message.zip $REPORTOUTFILE
ATTACHMENT_TEXT="stuck_order_report_tmp_$DATE.zip"
ATTACHMENT_CONTENTS_ENCODED="$( base64 $CURRENT_PATH/message.zip )"
VALUE="To:"$TO"
Subject: Email with Attachment
Content-Type: multipart/mixed;
boundary="a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a"
--a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a
Content-Type: multipart/alternative;
boundary="sub_a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a"
--sub_a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
--sub_a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
Hello ! This is the text content for the email body. Whatever modification is required has to happen here.
Ensure that the boundaries values are changed. Feel free to change the last two digits only.
Remember that the same change must reflect in both start of boundary and end of boundary.
--sub_a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a--
--a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a
Content-Type: attachment/zip; name="$ATTACHMENT_TEXT"
Content-Description: "$ATTACHMENT_TEXT"
Content-Disposition: attachment;filename="$ATTACHMENT_TEXT";
Content-Transfer-Encoding: base64
$ATTACHMENT_CONTENTS_ENCODED
--a3f166a86b56ff6c37755292d690675717ea3cd9de81228ec2b76ed4a15d6d1a--"
MESSAGE="$(echo "$VALUE" | base64)"
message="RawMessage.Data=$MESSAGE"
#message_edited=${message%??}
last_two_character=${message:(-2)}
last_one_character=${message:(-1)}
echo $last_two_character
echo $last_one_character
if [ "$last_two_character" == "==" ]; then
message_edited=${message%??}
else
message_edited=${message}
fi
if [ "$last_one_character" == "=" ]; then
message_edited=${message%??}
else
message_edited=${message}
fi
echo "$message_edited" > $CURRENT_PATH/message.txt
chmod 777 $CURRENT_PATH/message.txt
# trigger email
curl -v -X POST --trace "$CURRENT_PATH/trace.log" -H "Date: $date" -H "$auth_header" -H "$content_encoding" --data-binary "@$CURRENT_PATH/message.txt" --data-urlencode "$source" --data-urlencode "$action" "$endpoint"
rm -f $CURRENT_PATH/message.txt
rm -f $CURRENT_PATH/message.zip
rm -f $REPORTOUTFILE
答案 1 :(得分:0)
我不明白。如果我是对的,请告诉我。您正在发送csv,但是想要将其作为.zip?
获取可能会抛出错误,因为即使将文件作为zip文件接收,文件也不会被编码为zip。就像当你尝试用单词打开pdf时,它会显示加密的所有内容。
您是否在发送邮件之前尝试制作拉链? (使用zip命令或其他东西)