您可以按照以下步骤解决此问题:
在 Serverless 中配置 AWS Cognito 的用户池,并在 Cognito 设置中启用电子邮件验证。
在 Serverless.yml 文件中,添加'cognitoUserPool”资源,将以下代码示例中的 YOUR_USER_POOL_ID 和 YOUR_APP_CLIENT_ID 替换为您的用户池 ID 和应用程序客户端 ID:
resources:
Resources:
CognitoUserPool:
Type: AWS::Cognito::UserPool
Properties:
UserPoolName: YOUR_USER_POOL_NAME
AutoVerifiedAttributes:
- email
EmailVerificationMessage: "Your verification code is {####}. "
EmailVerificationSubject: "Your verification code"
AdminCreateUserConfig:
AllowAdminCreateUserOnly: true
VerificationMessageTemplate:
EmailMessage: Your verification code is {####}.
EmailSubject: Your verification code
EmailMessageByLink: Please use {##Verify Email##} as verification code to confirm your email address.
UsernameAttributes:
- email
CognitoUserPoolClient:
Type: "AWS::Cognito::UserPoolClient"
Properties:
ClientName: YOUR_APP_CLIENT_NAME
RefreshTokenValidity: 30
UserPoolId: !Ref CognitoUserPool
GenerateSecret: false
ExplicitAuthFlows:
- ADMIN_NO_SRP_AUTH
- USER_PASSWORD_AUTH
functions:
Register:
handler: handler.register
events:
- cognitoUserPool:
pool: YOUR_USER_POOL_ID
trigger: PreSignUp
这样,您的 Serverless 部署就可以发送确认电子邮件了。