1
I have the following structure to send emails by SendGrid:
import mail from '@sendgrid/mail';
function send(email_data) {
mail.setApiKey(process.env.SENDGRID_API_KEY);
const message = {
to: email_data.to,
from: email_data.from,
subject: email_data.subject,
text: email_data.text,
};
return mail.send(message);
}
export default send;
In my Controller, I call method send as follows:
import mail from '../../services/sendgrid';
const email_data = {
to: '[email protected]',
from: '[email protected]',
subject: 'Deposito realizado',
text: 'Foi feito um deposito na sua conta ...',
};
mail.send(email_data);
But the following error is displayed to me:
(node:7963) UnhandledPromiseRejectionWarning: TypeError: _sendgrid2.default.send is not a function
This will probably be import error. You exported the function
sendasdefault, but is trying to summon her asmail.send. Include in the code how you imported this module.– Andre
imported as follows. I put up
– Raphael Prado de Oliveira