簡體   English   中英

使用Node.js中的Azure SendGrid發送電子郵件

[英]Send an email using Azure SendGrid in Node.js

我正在閱讀文檔 ,以便使用SendGrid發送電子郵件:

var sendgrid = require('sendgrid')("username", "passowrd");

var email = new sendgrid.Email({
    to: 'user@company.com',
    from: 'user@company.com',
    subject: 'test mail',
    text: 'This is a sample email message.',
    html: 'This is a sample <b>HTML<b> email message.'
});

sendgrid.send(email, function(err, json){
    if(err) { return console.error(err); }
    console.log(json);
});

但是我得到了錯誤:

sendgrid.Email不是構造函數

我在各種項目中使用sendgrid,我一直在使用https://github.com/sendgrid/sendgrid-nodejs中的文檔。 我想知道Azure的文檔是否仍然是最新的...

如果您使用@sendgrid/mail軟件包並正確配置您的帳戶,則可以采用任何方法。 此代碼應工作:

const createSampleMessage = {
  to: 'user@company.com',
  from: 'user@company.com',
  subject: 'test mail',
  text: 'This is a sample email message.',
  html: 'This is a sample <b>HTML<b> email message.'
};
if (process.env.NODE_ENV !== "test") {
  await sgMail.send(createSampleMessage);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM