amazon-cognito-identity-js icon indicating copy to clipboard operation
amazon-cognito-identity-js copied to clipboard

Unable to send custom email messages

Open gsanjairaj opened this issue 6 years ago • 21 comments

I have custom message lambda trigger as below: exports.handler = (event, context, callback) => { console.log('context :', JSON.stringify(context, null, 2)); console.log('Received event:', JSON.stringify(event, null, 2)); event.response.emailMessage = 'Welcome to the service. Your confirmation code is ' + event.request.codeParameter; event.response.emailSubject = 'Custom message' event.response.smsMessage = 'Welcome to the service. Your confirmation code is ' + event.request.codeParameter; console.log('Received event:', JSON.stringify(event, null, 2)); // context.done(null, event); callback(null, event); };

And I have configured the lambda function under the triggers section for the custom message trigger as well. However, I am always getting the error as {"__type":"InvalidParameterException","message":"The message is empty."} while the user userPool.signUp method call.

AWS Cognito documentation is pathetic. please spend time to support the developers and provide proper documentation and samples.

gsanjairaj avatar Sep 11 '17 02:09 gsanjairaj

Thanks for your time and response. If i use {####}, i get the below response code : "InvalidParameterException" message: "The message is empty."

the code sample at http://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-identity-pools-working-with-aws-lambda-triggers.html is suggesting to use codeParameter. I am not sure why it humours you??

gsanjairaj avatar Sep 12 '17 23:09 gsanjairaj

The page you linked has a sample request with

"codeParameter": "####"

but also states

The message must include the code parameter, {####}, which is the placeholder for the verification code that is delivered to the user.

I'll assume this is a documentation error, so verify that the code parameter does include braces {}.

TrentBartlem avatar Sep 13 '17 00:09 TrentBartlem

Thanks again. As I said earlier, including {####} throws invalid parameter exception. Without the custom message trigger set, signup is working fine and even the template based email link / code works fine.

With the custom message trigger set and if I use just #### alone, i don't get any errors and a i receive an email. Interestingly, the email subject has the "custom message" subject, but the body has the default content from the "message customization" section of the user pool.

As I earlier said, the documents needs lot of improvement. really a lot.

gsanjairaj avatar Sep 13 '17 04:09 gsanjairaj

Hello,

I have traced the issue. I assume you are using custom message with link (correct?). In the case you are using links: to unblock you please use instead of "{##Click Here##}" instead of "{####}". In the meantime we are working on the fix.

vlekakis avatar Sep 28 '17 21:09 vlekakis

Nope. no improvement.

Yes, I use custom message with link. Here is the code that is use:

exports.handler = (event, context, callback) => { console.log('context :', JSON.stringify(context, null, 2)); console.log('Received event:', JSON.stringify(event, null, 2)); event.response.emailMessage = 'Welcome to the service. Please click {##Click Here##} to confirm your email Id'; event.response.emailSubject = 'Custom subject' callback(null, event); };

The email that I get has the subject - "Custom subject", while the message is retrieved from the default content in the "message customization" section of the user pool. I have set the lambda function for the custom message trigger under the triggers section of the user pool.

Why in the world, such a small straight forward functionality does not work in cognito?

gsanjairaj avatar Oct 03 '17 13:10 gsanjairaj

I have this same issue in my python lambda trigger. The subject changes to what I want, but...

These send an email with the default message from the user pool settings: "Please click {##Verify Email##}" "Please click Verify Email" % (event['region'], event['callerContext']['clientId'], event['userName']) That's a link still using {##Verify Email##}.

And all these respond with "An error occurred (InvalidParameterException) when calling the SignUp operation: The message is empty.": "Please click {####}" "Please click " + event['request']['codeParameter'] "Please click Verify Email" % (event['region'], event['callerContext']['clientId'], event['userName']) "Please click Verify Email" % (event['region'], event['callerContext']['clientId'], event['userName'], event['request']['codeParameter']) Those are links using {####}.

GDavisSS avatar Oct 03 '17 16:10 GDavisSS

Got this to work.

I worked with my boss who had a lot more javascript experience than i do. So she understood what was probably happening on the AWS side when it replaces the placeholder code parameter. We got custom message with link to work.

We tried making the emailMessage string as below with differing results: "Verify email {{##Verify Email##}}" resulted in default AWS email "Verify email {{####}}" resulted in a custom email, but the link to click showed up as ##. The link worked, but who wants to have users click ## for verification

In the end we went back to the code setting instead of link for verification type in the user pool. Inside the custom message trigger code we manually created the link exactly as it appears if you use link verification type setting. At the end of the link we did "confirmation_code={####}" and we got our custom email with a clickable link that works.

This is a workaround, but of course it should be fixed to work if user pool verification type is set to link.

GDavisSS avatar Oct 04 '17 16:10 GDavisSS

For me this setting is working: VerificationMessageTemplate: { DefaultEmailOption: "CONFIRM_WITH_LINK", EmailMessageByLink: 'This text is not part of the link. {##This text will be the link##}', EmailSubjectByLink: 'subject' },

It is sending out a confirmation e-mail with a link in it.

maartenvandillen avatar Oct 24 '17 08:10 maartenvandillen

Any news on that - aws just sends the code but I have verified that the emailMessage property of the response contains {####} but its not using the template.

wolfmanfx avatar Oct 26 '17 10:10 wolfmanfx

I know this is a new addition to cognito but it's not usable if you can't onboad users without giving them the easy option of a link in an email the same style as your application.

It's only really useful if the plain URL supplied (not the entire <a> tag), or supply placeholders for user_name, confirmation_code, etc individually.

The default URL is something like https://[domain].auth.us-east-1.amazoncognito.com/confirmUser?client_id=[client_id]&user_name=[username]&confirmation_code=[code]

@GDavisSS I'm interested to know how you constructed your link, since the default one that Cognito uses contains the user_name, which there is no placeholder for. Did you link to a different handler and process the verification somehow manually, maybe by asking the user to enter their username?

milesjordan avatar Nov 05 '17 12:11 milesjordan

@maartenvandillen - I'm really interested in knowing how you got the link to work in the Lambda Trigger.

ankitaghurye avatar Nov 21 '17 21:11 ankitaghurye

@ankitaghurye I did not use any trigger. The fragment I mentioned is part of a script that creates the user pool.

maartenvandillen avatar Nov 22 '17 07:11 maartenvandillen

Is there any progress on this? I've configured email verification to use the "Link" instead of "Code", but all the emails are coming through with a code. I left the message as default which is:

Please click the link below to verify your email address. {##Verify Email##}

Edit: Note that I'm using App Integration feature

drcoll avatar Dec 13 '17 18:12 drcoll

Mine doesn't even send the email. If I look in cloud watch, I can see that {####} is in there, but again, it doesn't even send it. I'm able to handle every other trigger-source just fine, but the SignUp one is little wonky.

MattEttler avatar Dec 13 '17 23:12 MattEttler

AWS Cognito team - Is there any ETA to fix this issue? it has been months together people are waiting for you guys to have proper fix. why? Please don't push people towards firebase.

gsanjairaj avatar Dec 13 '17 23:12 gsanjairaj

I can send and receive the custom email from my Lambda function, but cant send a confirmation code for CustomMessage_SignUp or a temp password for CustomMessage_AdminCreateUser.

I am using event.request.codeParameter but it just returns {####}. I have tried numerous different ways but cant seem to get a code or temp password in the email template.

Does anyone have any ideas/suggestions?? My application has already been built to use the input of the 6 digit code as well (cant use link).

Thanks

mattcoll avatar Dec 14 '17 06:12 mattcoll

@gsanjairaj were you able to figure out some workaround for sending custom email messages? I'm running into the exact same error as you.

stevewillard avatar Jan 09 '18 14:01 stevewillard

No, not yet. Currently, I left it with default link as @drcoll suggested -


Hi, Thanks for registering. Your registration is successful. Please click the link below to verify your email address. {##Verify Email##}


The "verify email" link goes to amazon cognito domain, I am yet to spend time further on this, to send it to my website and thereafter verify email through Cognito API. Another Option is to use firebase API for custom signins and then use Cognito Identity to avoid all the above issues. check the below discussions: https://github.com/aws/amazon-cognito-identity-js/issues/608#issuecomment-353595734 https://github.com/aws/amazon-cognito-identity-js/issues/508 https://github.com/aws/amazon-cognito-identity-js/issues/500 https://github.com/aws/amazon-cognito-auth-js/issues/3 https://github.com/aws/amazon-cognito-auth-js/issues/55

gsanjairaj avatar Jan 09 '18 15:01 gsanjairaj

Hi,

We found a workaround for this issue. In your UserPool>Message Customizations, change the "Verification type" to "code". Then in your Lambda trigger for "Custom Message" you can construct the Url for confirming the user:

`exports.handler = (event, context, callback) => {

if(event.triggerSource === "CustomMessage_SignUp") {
        event.response.emailSubject = "Welcome to our website";
        event.response.emailMessage = "Follow this link to finish the registration:<br /><a href=https://{yourCognitoDomain/confirmUser?client_id={yourClientId}&user_name=" + event.request.userAttributes.sub + "&confirmation_code=" + event.request.codeParameter +">Click Here</a>";
    }   console.log(event); context.done(null, event);};

`

Gcm84 avatar Jan 17 '18 17:01 Gcm84

@Gcm84 Thank you!!! Your great answer work for me!

yudai524 avatar Jan 24 '18 12:01 yudai524

@maartenvandillen I am using the same setting while creating my user pool but it gives me a

UnexpectedParameter: Unexpected key 'VerificationMessageTemplate' found in params error. Do you happen to know why would Cognito throw this error?

Ashirogi-Muto avatar Feb 14 '18 13:02 Ashirogi-Muto