sending mail on user create working

This commit is contained in:
dimitar 2024-11-02 21:11:20 +01:00
parent 847ed031db
commit 7ecb1fea2e
3 changed files with 31 additions and 16 deletions

View File

@ -16,5 +16,5 @@ SMTP_PORT=465
SMTP_USER=mailer@imk.mk SMTP_USER=mailer@imk.mk
SMTP_PASSWORD=76Avtostoperski76 SMTP_PASSWORD=76Avtostoperski76
SMTP_FROM=mailer@imk.mk SMTP_FROM=mailer@imk.mk
FRONTEND_URL=https://imk.mk FRONTEND_URL=http://localhost:5173
ADMIN_EMAIL=petrovskidimitar@yandex.com ADMIN_EMAIL=petrovskidimitar@yandex.com

View File

@ -43,15 +43,22 @@ export class AdminService {
} }
async createUser(createUserDto: CreateUserDto) { async createUser(createUserDto: CreateUserDto) {
const hashedPassword = await bcrypt.hash(createUserDto.password, 10); try {
const hashedPassword = await bcrypt.hash(createUserDto.password, 10);
return this.prisma.user.create({ const user = await this.prisma.user.create({
data: { data: { ...createUserDto, password: hashedPassword},
...createUserDto, });
password: hashedPassword, try {
isAdmin: createUserDto.isAdmin, await this.emailService.sendWelcomeEmail(user.email, user.name );
}, console.log('Welcome email sent successfully');
}); } catch (error) {
console.log('Error sending welcome email:', error);
}
return user;
} catch (error) {
console.error('Error creating user:', error );
throw error;
}
} }
async updateDocument( async updateDocument(

View File

@ -10,13 +10,21 @@ export class EmailService {
to: email, to: email,
subject: 'Welcome to IMK Platform', subject: 'Welcome to IMK Platform',
html: ` html: `
<h1>Welcome ${name}!</h1> <div style="font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto;">
<p>Your account has been created successfully.</p> <h1 style="color: #2563eb;">Welcome to IMK Platform!</h1>
<p>You can now login to access your documents.</p> <p>Dear ${name},</p>
<p>Please use the following link to reset your password: </p> <p>Thank you for joining IMK Platform. Your account has been created successfully.</p>
<p>You can now log in to access your documents and start collaborating with your team.</p>
<p>If you have any questions or need assistance, please don't hesitate to contact our support team.</p>
<div style="margin: 30px 0;">
<a href="${process.env.FRONTEND_URL}/login"
style="background-color: #2563eb; color: white; padding: 12px 24px; text-decoration: none; border-radius: 4px;">
Login to Your Account
</a>
</div>
<p>Best regards,<br>IMK Team</p> <p>Best regards,<br>IMK Team</p>
`, </div>
`,
}); });
} }