これまでに私が達成したのはこれです。私はgapi
クライアントライブラリを使用しています。
まず最初に、あなたの電子メールを正しく構築する必要があります。私の実際の例ですが、どの部分の間にも空白行が必要です。すべての部分を配列に追加し、your_array.join('\r\n')
を使用して電子メールを作成することができます。
Content-Type: multipart/mixed; boundary="your_boundary"
MIME-Version: 1.0
From: [email protected]
To: [email protected]
Subject: Test
Reply-To: [email protected]
Date: Wed Jan 04 2017 10:47:11 GMT-0500 (EST)
--your_boundary
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
<p>Boundary, multi attachs<br />
<em><strong>--<br />
With Regards</strong></em></p>
--your_boundary
Content-Type: image/png
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="sort_asc.png"
YOUR_BASE64_ENCODED_DATA
--your_boundary
Content-Type: image/png
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="sort_both.png"
YOUR_BASE64_ENCODED_DATA
--your_boundary
Content-Type: image/png
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="sort_desc.png"
YOUR_BASE64_ENCODED_DATA
--your_boundary--
次に、電子メールを送信するためにgapiのクライアントを使用しています。 sendMessage
は、gapiのオンラインドキュメントが提供する機能です。電子メールを送信する前に、Base64URLにメールを暗号化する必要があります。私はここからエンコードライブラリーを得た:https://www.npmjs.com/package/js-base64
sendMessage = function(userId, email, callback) {
var request = gapi.client.gmail.users.messages.send({
'userId': userId,
'resource': {
'raw': email
}
});
request.execute(callback);
}
sendMessage('me', Base64.encodeURI(email), function(resp) {
if(resp.labelIds && resp.labelIds.indexOf('SENT') > -1) {
console.log('Your email has been sent.');
}else {
console.log('Something went wrong');
}
});
は、添付ファイルのように見えるライブラリJSに組み込まれている、まだませんが、手動でエンドポイントを呼び出すことができない理由.. –
https://developers.google .com/gmail/api/guides/uploads#resumable –
私は一晩中私の頭を叩いてドキュメントからgmail apiを見つけて、ノードメーラの魅力のように動作するamazon sesに切り替えました。 –