amazon-archives / amazon-cognito-identity-js

Amazon Cognito Identity SDK for JavaScript
Other
985 stars 454 forks source link

Get verification code in lambda for external mail service #623

Open jkettmann opened 6 years ago

jkettmann commented 6 years ago

I'm using SendGrid as an external email service to send custom transactional emails. What I would like to do is to send a custom email verification including the code via SendGrid. I use auto confirmation, so to send the verification code I need to use.

cognitoUser.getAttributeVerificationCode('email' ...

I have a trigger on CustomMessage. My lambda is called and everything is working fine except I can't get the verification code to deliver it to SendGrid and render it in my email template. I could only find codeParameter which is {####}.

So how can I get the verification code to send it to external services?

This is my lambda.

'use strict';
const sgMail = require('@sendgrid/mail');

sgMail.setApiKey(process.env.SEND_GRID_API_KEY);
sgMail.setSubstitutionWrappers('{{', '}}');

module.exports.sendMail = (event, context, callback) => {
  console.log(event);

  if (event.request.userAttributes.email) {
    const msg = {
      template_id: 'someTemplateId',
      to: event.request.userAttributes.email,
      from: fromEmail,
      substitutions: {
        verificationCode: event.request.codeParameter,
      },
    };
    sgMail.send(msg)
      .then(() => context.done(null, event))
      .catch((error) => {
        console.log("sgMail.send failed",  error);
        context.done(null, event);
      });
  } else {
      console.log("Failed");
      context.done(null, event);
  }
};
jkettmann commented 6 years ago

Could anybody help with this? We are moving to production and I still couldn't find a real solution for this. I think I could set custom HTML code inside the Lambda which would be sent out via AWS, but that's not really what I'm looking for...

Any solution for sending the verification code via a third party service?

itrestian commented 6 years ago

This is not possible at this point. We do have a roadmap item to let users configure other providers. However, I cannot comment on the availability.

itsTeknas commented 6 years ago

I'm facing the same problem. I can't even get my SES Email limit increased due to some silly bounce and complaints compliance which i don't understand.

All i want to do is send the verification code form my own domain email id.