我正在编写一些代码,通过Mailgun邮件服务发送带附件的电子邮件。他们在API文档中使用CURL给出了以下示例,我需要弄清楚如何在Node.js中执行相同的操作(最好使用Request库)。
curl -s -k --user api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0 \
https://api.mailgun.net/v2/samples.mailgun.org/messages \
-F from='Excited User <me@samples.mailgun.org>' \
-F to='obukhov.sergey.nickolayevich@yandex.ru' \
-F cc='sergeyo@profista.com' \
-F bcc='serobnic@mail.ru' \
-F subject='Hello' \
-F text='Testing some Mailgun awesomness!' \
-F html='\<html\>HTML version of the body\<\html>' \
-F attachment=@files/cartman.jpg \
-F attachment=@files/cartman.png
我的当前代码(Coffescript)如下所示:
r = request(
url: mailgun_uri
method: 'POST'
headers:
'content-type': 'application/x-www-form-urlencoded'
body: email
(error, response, body) ->
console.log response.statusCode
console.log body
)
form = r.form()
for attachment in attachments
form.append('attachment', fs.createReadStream(attachment.path))
mailgun_uri
中吗?类似这样:url = "https://api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0@api.mailgun.net/v2/samples.mailgun.org/log";
我在我的答案中添加了一些 nodemailer 的代码。 - zemirco