1
我正在嘗試使用需要mailgun服務發送電子郵件的phantomjs來製作應用程序。由於沒有官方的mailgun phantomjs庫,因此我在電子郵件中附加文件時遇到了一些麻煩。電子郵件已成功發送,但我沒有看到任何附件。Mailgun - 在phantomjs中附加文件
下面是代碼:
function ObjToQs(obj) {
var str = "";
for (key in obj) {
str += key + '=' + obj[key] + '&';
}
str = str.slice(0, str.length - 1);
return str;
}=
var page = require('webpage').create(),
url = 'https://api.mailgun.net/v3/sandboxbxxxxxxxxxxxxxxxxxxxxxxxx.mailgun.org/messages',
data = {
from: "Ganesh <[email protected]>",
to: "[email protected]",
subject: "subject!",
text: "Body",
attachment: '/path/test.txt'
};
console.log(ObjToQs(data));
page.customHeaders = {'Authorization': 'Basic ' + btoa('api:key-xxxxxxxx')};
page.open(url, 'post', ObjToQs(data), function (status) {
if (status !== 'success') {
console.log('FAIL to load the log');
console.log(status);
} else {
console.log('Log success');
var result = page.evaluate(function() {
return document.body.innerText;
});
console.log("log Result: " + result);
phantom.exit();
}
});
我該怎麼辦?
謝謝!