2017-03-17 7 views
1

電子メールに添付ファイルとして別の種類のファイルを送信できるかどうかは疑問でした。私はcUrlを使ってテキストファイルを送る方法しか知りません。誰かが私の目標をどのように達成できるかの例をいくつか教えてもらえますか?cURL Mail Attachment(想像すると、.exeファイル、.rar/.zipファイル)

は、これは私がこれまで持っているものです。

curl --url "smtps://smtp.gmail.com:465" --mail-from "[email protected]" --mail-rcpt "[email protected]" --ssl --user "[email protected]:password" --upload-file "C:\Folder\File.txt" 

は、すべての努力をありがとう!

答えて

0

multipart/mixedコンテンツを使用して、テキスト本文と各バイナリ添付ファイルを送信できます。バイナリファイルは、BASE64でエンコードされており、attachmentとして送信されていることを

From: Some Name <[email protected]> 
To: Some Name <[email protected]> 
Subject: example of mail 
Reply-To: Some Name <[email protected]> 
Cc: 
MIME-Version: 1.0 
Content-Type: multipart/mixed; boundary="MULTIPART-MIXED-BOUNDARY" 

--MULTIPART-MIXED-BOUNDARY 
Content-Type: multipart/alternative; boundary="MULTIPART-ALTERNATIVE-BOUNDARY" 

--MULTIPART-ALTERNATIVE-BOUNDARY 
Content-Type: text/plain; charset=utf-8 
Content-Transfer-Encoding: base64 
Content-Disposition: inline 

This is an email example. This is text/plain content inside the mail. 
--MULTIPART-ALTERNATIVE-BOUNDARY-- 
--MULTIPART-MIXED-BOUNDARY 
Content-Type: application/octet-stream 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment; filename="file.rar" 
<HERE BASE64 ENCODED RAR FILE> 


--MULTIPART-MIXED-BOUNDARY 
Content-Type: application/octet-stream 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment; filename="file.zip" 
<HERE BASE64 ENCODED ZIP FILE> 


--MULTIPART-MIXED-BOUNDARY-- 

注:ここでは

は、テキストファイルを表示し、2つのバイナリファイルを添付するために使用できるファイルのテンプレートです。ここ
は、このファイルを作成するの一例であり、bashスクリプトを使って電子メールを送信:

#!/bin/bash 

rtmp_url="smtp://smtp.gmail.com:587" 
rtmp_from="[email protected]" 
rtmp_to="[email protected]" 
rtmp_credentials="[email protected]:secretpassword" 

file_upload="data.txt" 

echo "From: Some Name <$rtmp_from> 
To: Some Name <$rtmp_to> 
Subject: example of mail 
Reply-To: Some Name <$rtmp_from> 
Cc: 
MIME-Version: 1.0 
Content-Type: multipart/mixed; boundary=\"MULTIPART-MIXED-BOUNDARY\" 

--MULTIPART-MIXED-BOUNDARY 
Content-Type: multipart/alternative; boundary=\"MULTIPART-ALTERNATIVE-BOUNDARY\" 

--MULTIPART-ALTERNATIVE-BOUNDARY 
Content-Type: text/plain; charset=utf-8 
Content-Transfer-Encoding: base64 
Content-Disposition: inline 

This is an email example. This is text/plain content inside the mail. 
--MULTIPART-ALTERNATIVE-BOUNDARY-- 
--MULTIPART-MIXED-BOUNDARY 
Content-Type: application/octet-stream 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment; filename=\"file.rar\"" > "$file_upload" 

# convert file.rar to base64 and append to the upload file 
cat file.rar | base64 >> "$file_upload" 

echo "--MULTIPART-MIXED-BOUNDARY 
Content-Type: application/octet-stream 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment; filename=\"file.zip\"" >> "$file_upload" 

# convert file.zip to base64 and append to the upload file 
cat file.zip | base64 >> "$file_upload" 

# end of uploaded file 
echo "--MULTIPART-MIXED-BOUNDARY--" >> "$file_upload" 

# send email 
echo "sending ...." 
curl -s "$rtmp_url" \ 
    --mail-from "$rtmp_from" \ 
    --mail-rcpt "$rtmp_to" \ 
    --ssl -u "$rtmp_credentials" \ 
    -T "$file_upload" -k --anyauth 
res=$? 
if test "$res" != "0"; then 
    echo "sending failed with: $res" 
else 
    echo "OK" 
fi 

受信した電子メールがinlinetext/plain文書及びタイプapplication/octet-streamattachment文書の両方があります:

enter image description here

関連する問題