Two different events with different email addresses are sent to the first email address

Hello, I have been using novu for a short time in my work. I have been using it regularly to send emails . I am working with nestjs framework. My previous tasks were only related to sending one email at a time, however, I am on a task where I need to send two consecutive emails, to two different events: one to notify the user and one to notify an administrator. My problem is that, although I send both events with the specific subscriber information to each one, both emails always arrive only to one of the emails. I have a method in my communication service to send any type of event and content:
typescript
async sendEmail(
trigger: string,
subscriber: { subscriberId: string; email: string },
payload: any,
): Promise<any> {
const result = await this.novu.trigger(trigger, {
to: subscriber,
payload: payload,
});

return result.data;
}
typescript
async sendEmail(
trigger: string,
subscriber: { subscriberId: string; email: string },
payload: any,
): Promise<any> {
const result = await this.novu.trigger(trigger, {
to: subscriber,
payload: payload,
});

return result.data;
}
When I use it, I call runs with waiting for each step to be executed, inside a try/catch
typescript
try {
// Notify user
await this.notificationService.sendEmail(
'lockers-reservation-user',
{
subscriberId: `${result.subscriber_id}`,
email: result.email,
},
{
...result,
},
);

// Notify admin
await this.notificationService.sendEmail(
'lockers-reservation-admin',
{
subscriberId: '0',
email: process.env.LOCKERS_ADMIN_EMAIL,
},
{
admin: process.env.LOCKERS_ADMIN_NAME,
...result,
},
);
} catch (error) {
console.error(error);
}
typescript
try {
// Notify user
await this.notificationService.sendEmail(
'lockers-reservation-user',
{
subscriberId: `${result.subscriber_id}`,
email: result.email,
},
{
...result,
},
);

// Notify admin
await this.notificationService.sendEmail(
'lockers-reservation-admin',
{
subscriberId: '0',
email: process.env.LOCKERS_ADMIN_EMAIL,
},
{
admin: process.env.LOCKERS_ADMIN_NAME,
...result,
},
);
} catch (error) {
console.error(error);
}
When calling each execution of the method to send the email I have checked that each email is the correct one, and it is always the one I have indicated, however both still arrive only to the user's notification email. Any idea what might be going on?
No description
No description
No description
5 Replies
Zac Clifton
Zac Clifton13mo ago
@George
Pawan Jain
Pawan Jain13mo ago
@Esteban Alvarado By any chance, admin email and subscriber email could be same? Could you please share transactionId ? I will check the root cause
Esteban Alvarado
Esteban AlvaradoOP13mo ago
Hey, Thanks! I print first the to object of each event trigger, and as you can see each email and subscriber id is different. Also, I'm showing the result data with the transactions id.
{ subscriberId: '42', email: '[email protected]' }
{ subscriberId: '0', email: '[email protected]' }
{
data: {
acknowledged: true,
status: 'processed',
transactionId: '524abcf0-91e9-4146-a1e3-75b5f59679a4'
}
} {
data: {
acknowledged: true,
status: 'processed',
transactionId: '9c7e11c4-aaf2-4f54-a375-73d1c59fff08'
}
}
{ subscriberId: '42', email: '[email protected]' }
{ subscriberId: '0', email: '[email protected]' }
{
data: {
acknowledged: true,
status: 'processed',
transactionId: '524abcf0-91e9-4146-a1e3-75b5f59679a4'
}
} {
data: {
acknowledged: true,
status: 'processed',
transactionId: '9c7e11c4-aaf2-4f54-a375-73d1c59fff08'
}
}
I also attach a screenshot of the subscribers table in the novu dashboard.
No description
Esteban Alvarado
Esteban AlvaradoOP13mo ago
@Pawan Jain I have also tried to use a direct email address in the code, instead of the environment variable and it still skips sending to this address and still sends both emails to the user. @Pawan Jain Hello, I have managed to solve the problem, I was sending in the payload a property called email, which overwrote the email to which it should be sent. Thanks anyway!
Pawan Jain
Pawan Jain13mo ago
Thanks for the update @Esteban Alvarado As email is system variable, it should not be used as payload dynamic variable
Want results from more Discord servers?
Add your server