Hey! , i am trying to add the forgot-password func...
# support-questions-legacy
d
Hey! , i am trying to add the forgot-password functionality to my app , i was able to get it to send the mail but currently it sends it using the supertokens email, i want to configure it to use my mail I have added the below lines to supertokens init
Copy code
emailDelivery: {
                    override: (originalImplementation) => {
                        return {
                            ...originalImplementation,
                            service: new EmailVerificationSMTPService({
                                smtpSettings,
                            }),
                            sendEmail: async function (input) {
                                if (input.type === 'PASSWORD_RESET') {
                                    // You can change the path, domain of the reset password link,
                                    // or even deep link it to your mobile app
...
r
hey @devdev4117
the email verification config doesn't get password reset emails. That will come in the emailpassword or thirdpartyemailpassword recipe config
d
Hey , yup i changed it to the following import import { SMTPService } from 'supertokens-node/recipe/emailpassword/emaildelivery/index.js';
Copy code
sendEmail: async function (input) {
                                if (input.type === 'PASSWORD_RESET') {
                                    console.log(input);
                                    // You can change the path, domain of the reset password link,
                                    // or even deep link it to your mobile app
                                    return originalImplementation.sendEmail({
                                        ...input,
                                        service: new SMTPService({
                                            smtpSettings,
                                        }),
i tried adding service on top aswell under emaildelivery
r
can i see your full init code?
d
r
can you enable backend debug logs and show the output for when you call the password reset API? Note that the API will only be send the email if the email ID used already exists in supertokens
d
yup , this is understood, only issue is it sends thje email from noreply@supertokens.io
r
thats cause you call the originalImplementation in the sendEmail function. If you want to send it using your own email, see the smtp service we provide
d
I have configured the smtp service let smtpSettings = { host: 'smtp.gmail.com', authUsername: process.env.SMTP_USERNAME, // this is optional. In case not given, from.email will be used password: process.env.SMTP_PASSWORD, port: 465, from: { name: process.env.SMTP_USERNAME, email: process.env.SMTP_USERNAME, }, secure: true, };
service: new SMTPService({ smtpSettings, }),
should i remove the orignal implementation call?
r
oh. In this case keep the original implementation call.
but in the code you sent, i didn't see this setting
d
Copy code
sendEmail: async function (input) {
                                if (input.type === 'PASSWORD_RESET') {
                                    console.log(input);
                                    // You can change the path, domain of the reset password link,
                                    // or even deep link it to your mobile app
                                    return originalImplementation.sendEmail({
                                        ...input,
                                        service: new SMTPService({
                                            smtpSettings,
                                        }),
                                        passwordResetLink:
                                            input.passwordResetLink.replace(
                                                // This is: `${websiteDomain}${websiteBasePath}/reset-password`
                                                `${process.env.WEBSITE_DOMAIN}/reset-password`,
                                                `${process.env.WEBSITE_DOMAIN}/reset-password`
                                            ),
                                    });
                                }
                                return originalImplementation.sendEmail(input);
                            },
here is the entire call for sendEmail
i have added the setting as a variable
r
oh right.. ok.. So this needs to be done in a different way
are you using JS or TS?
d
js
r
cause i don't think the above code is even correct
d
ohh, is there any change i should make, i tried everything that was there in the docs
r
The structure needs to be like this. I would recommend you see the types.
Copy code
EmailPassword.init({
    emailDelivery: {
        service: new SMTPService({
            smtpSettings
        }),
        override: (oI) => {
            return {
                ...oI,
                sendEmail: async function (input) {
                    // TODO..
                }
            }
        }
    }
})
d
i had done this previously as well, tried again, still does not work
r
is your code correct for sure? I would suggest you try using TS and make sure it compiles
and then tell me if even after compilation it doesnt work
d
i checked the types, cant really shift the codebase to ts now , But when i dont use the config as a variable like this,
Copy code
recipeList: [
        EmailPassword.init({
            override: {
                emailDelivery: {
                    service: new SMTPService({
                        config: {
                            host: 'stmp.gmail.com',
                            authUsername: process.env.SMTP_USERNAME, // this is optional. In case not given, from.email will be used
                            password: process.env.SMTP_PASSWORD,
                            port: 465,
                            from: {
                                name: process.env.SMTP_USERNAME,
                                email: process.env.SMTP_USERNAME,
                            },
                            secure: true,
                        },
                    }),
I get the following error
r
hmm. Can you please open an issue about this on our github? Along with how to replicate it. We will check it out
d
alright sure
r
thank you!
38 Views