Я следую за документацией, чтобы отправить электронное письмо с использованием SendGrid:
var sendgrid = require('sendgrid')("username", "passowrd");
var email = new sendgrid.Email({
to: '[email protected]',
from: '[email protected]',
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: '[email protected]',
from: '[email protected]',
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);
}