linux Curl:发送带有附件的电子邮件->错误->警告:非法格式化的内容类型字段

kognpnkq  于 12个月前  发布在  Linux
关注(0)|答案(1)|浏览(171)

代码:

SERVER='smtp.abc.com'
PORT='587'
USER='[email protected]'
PASS='12134'
SENDER_ADDRESS="$USER"
SENDER_NAME='SENDER'
RECIPIENT_NAME='testname'
RECIPIENT_ADDRESS='[email protected]'
SUBJECT='status'
MESSAGE='Hi all,
'
ATTACHMENT_FILE='/home/ubuntu/aa/aa.log'
ATTACHMENT_TYPE="$(file --mime-type '$ATTACHMENT_FILE' | sed 's/.*: //')"

curl --ssl-reqd --url "smtp://$SERVER:$PORT" \
    --user "$USER:$PASS" \
    --mail-from "$SENDER_ADDRESS" \
    --mail-rcpt "$RECIPIENT_ADDRESS" \
    --header "Subject: $SUBJECT" \
    --header "From: $SENDER_NAME <$SENDER_ADDRESS>" \
    --header "To: $RECIPIENT_NAME <$RECIPIENT_ADDRESS>" \
    --form '=(;type=multipart/mixed' --form "=$MESSAGE;type=text/plain" \
    --form "file=@$ATTACHMENT_FILE;type=$ATTACHMENT_TYPE;encoder=base64" --form '=)'

字符串
我正在尝试发送电子邮件附件,但收到以下错误:

Warning: Illegally formatted content-type field!
curl: option --form: is badly used here
curl: try 'curl --help' or 'curl --manual' for more information

n3h0vuf2

n3h0vuf21#

curl抱怨的唯一一个非硬编码的内容类型(Warning: Illegally formatted content-type field!)是您的ATTACHMENT_TYPE
尝试获取其内容,它会给你一个错误:

>>> echo $ATTACHMENT_TYPE
cannot open `$ATTACHMENT_FILE' (No such file or directory)

字符串
ATTACHMENT_FILE中的单引号改为双引号,这样就可以了:

ATTACHMENT_TYPE="$(file --mime-type "$ATTACHMENT_FILE" | sed 's/.*: //')"

相关问题