i试图使用SES API将附件作为CSV文件的Zipped content发送。CSV文件的大小接近3MB。我不使用任何SDK,并使用卷曲和API端点从bash壳中进行。
代码有效,我也将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"
以下摘要最终工作
## 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
我不明白。让我知道我是否正确。您正在发送CSV,但您想以.zip的形式获得它?
错误可以丢弃,因为即使文件作为zip接收到该文件,该文件也不会编码为zip。就像您尝试在Word中打开PDF时,它将显示所有内容。
在发送邮件之前,您是否尝试过进行拉链?(使用zip命令或其他(