有没有办法从 Twilio 功能发送电子邮件?我知道我们可以使用sendgrid。我正在寻找一个更简单的解决方案。
最佳答案
Twilio 布道者在这里。 👋
截至目前,您可以使用 SendGrid来自 Twilio Function .下面的代码为我完成了这项工作,我刚刚通过一个函数发送了一封电子邮件
exports.handler = function(context, event, callback) {
const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const msg = {
to: 'sjudis@twilio.com',
from: 'test@example.com',
subject: 'Sending with SendGrid is Fun',
text: 'and easy to do anywhere, even with Node.js',
html: '<strong>and easy to do anywhere, even with Node.js</strong>',
};
sgMail.send(msg)
.then(() => {
callback(null, 'Email sent...');
})
.catch((e) => {
console.log(e);
})
};
上面的电子邮件最有可能以
test@example.com
的形式出现在垃圾邮件中不是一个非常值得信赖的电子邮件地址。如果您想从您自己的域发送电子邮件,则需要额外的配置。要在函数内部运行代码,您必须确保安装
sendgrid/mail
邮件依赖并在 the function configuration 中提供 sendgrid token .如果您想使用此功能供电,例如您必须确保您返回的消息有效 TwiML . :) 当您创建一个新函数时,您将获得有关如何执行此操作的示例。
希望有帮助。 :)
关于Twilio - 从函数发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55285374/