[ad_1]
To send e-mails in a production environment, use services like Sendgrid.
Verify the e-mail address on the Sender Management page and create the SendGrid API key on the API keys page.
import nodemailer from 'nodemailer';
(async () => {
const emailConfiguration = {
auth: {
user: process.env.EMAIL_USERNAME, // 'apikey'
pass: process.env.EMAIL_PASSWORD
},
host: process.env.EMAIL_HOST, // 'smtp.sendgrid.net'
port: process.env.EMAIL_PORT, // 465
secure: process.env.EMAIL_SECURE, // true
};
const transport = nodemailer.createTransport(emailConfiguration);
const info = await transport.sendMail({
from: '"Sender" <[email protected]>',
to: '[email protected], [email protected]',
subject: 'Subject',
text: 'Text',
html: '<b>Text</b>'
});
console.log('Message sent: %s', info.messageId);
})();
Demo
The demo with the mentioned example is available here.
Related reading
[ad_2]
Source link