Search code examples
emailconfiguration-filessendgridone-time-passwordwso2-identity-server

WSO2 Identity Server OTP Email Configuration for SendGrid


I am getting crazy in setting email configuration for sendgrid.

I have followed steps for configuring Email OTP. When I try the email is not being sent & in the logs I find the following exception:

[2019-01-23 13:15:42,756] ERROR {org.wso2.carbon.event.output.adapter.email.EmailEventAdapter} -  Event dropped at Output Adapter 'EmailPublisher' for tenant id '-1234', Error in message format, null
javax.mail.AuthenticationFailedException
    at javax.mail.Service.connect(Service.java:306)
    at javax.mail.Service.connect(Service.java:156)
    at javax.mail.Service.connect(Service.java:105)
    at javax.mail.Transport.send0(Transport.java:168)
    at javax.mail.Transport.send(Transport.java:98)
    at org.wso2.carbon.event.output.adapter.email.EmailEventAdapter$EmailSender.run(EmailEventAdapter.java:306)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

Entire documentation is about how to Configure Gmail as the email OTP provider. I have done configuration based on the understanding I got from basic doc.

Please find configurations under the section in the /repository/conf/identity/application-authentication.xml configurations that I tried:

 <AuthenticatorConfig name="EmailOTP" enabled="true">
        <Parameter name="GmailClientId">gmailClientIdValue</Parameter>
        <Parameter name="GmailClientSecret">gmailClientSecretValue</Parameter>
        <Parameter name="SendgridAPIKey">S********1sLhYrS4_h7J1ehoBWA</Parameter>
        <Parameter name="GmailRefreshToken">gmailRefreshTokenValue</Parameter>
        <Parameter name="GmailEmailEndpoint">https://www.googleapis.com/gmail/v1/users/[userId]/messages/send</Parameter>
        <Parameter name="SendgridEmailEndpoint">https://api.sendgrid.com/api/mail.send.json</Parameter>
        <Parameter name="accessTokenRequiredAPIs">Gmail</Parameter>
        <Parameter name="apiKeyHeaderRequiredAPIs">Sendgrid</Parameter>
        <Parameter name="SendgridFormData">SendgridFormData</Parameter>
        <Parameter name="SendgridURLParams">sc</Parameter>
        <Parameter name="GmailAuthTokenType">Bearer</Parameter>
        <Parameter name="GmailTokenEndpoint">https://www.googleapis.com/oauth2/v3/token</Parameter>
        <Parameter name="SendgridAuthTokenType">Bearer</Parameter>
        <Parameter name="redirectToMultiOptionPageOnFailure">false</Parameter>
    </AuthenticatorConfig>

I think it's not documented well for sendgrid or I am not able to find it. Could anyone provide some reference or solution for the same? Thanks in advance.


Solution

  • This error will be thrown when Gmail blocks an external party to sign in to the account. Turing on 'Less secure app access' at https://myaccount.google.com/security will solve this issue.