diff --git a/.env.development b/.env.development index da32b80..e47f69e 100644 --- a/.env.development +++ b/.env.development @@ -16,4 +16,11 @@ DB_HOST=202.218.61.226 DB_USER=readonly DB_PASSWORD=aAjmFW12iHKW84l1 DB_DATABASE=qpartners -DB_PORT=3306 \ No newline at end of file +DB_PORT=3306 + +SMTP_HOST=autodiscover.qcells.com +SMTP_PORT=25 +SMTP_SECURE=true +SMTP_USER=hss404.u021@cleverse.dev +SMTP_PASSWORD=0000 +SMTP_FROM=qsalesplatform@qcells.com \ No newline at end of file diff --git a/.env.localhost b/.env.localhost index 138c28f..482880c 100644 --- a/.env.localhost +++ b/.env.localhost @@ -16,4 +16,11 @@ DB_HOST=202.218.61.226 DB_USER=readonly DB_PASSWORD=aAjmFW12iHKW84l1 DB_DATABASE=qpartners -DB_PORT=3306 \ No newline at end of file +DB_PORT=3306 + +SMTP_HOST=autodiscover.qcells.com +SMTP_PORT=25 +SMTP_SECURE=true +SMTP_USER=hss404.u021@cleverse.dev +SMTP_PASSWORD=0000 +SMTP_FROM=qsalesplatform@qcells.com diff --git a/.env.production b/.env.production index 1738ee7..72caa0d 100644 --- a/.env.production +++ b/.env.production @@ -14,4 +14,11 @@ DB_HOST=202.218.61.226 DB_USER=readonly DB_PASSWORD=aAjmFW12iHKW84l1 DB_DATABASE=qpartners -DB_PORT=3306 \ No newline at end of file +DB_PORT=3306 + +SMTP_HOST=autodiscover.qcells.com +SMTP_PORT=25 +SMTP_SECURE=true +SMTP_USER=hss404.u021@cleverse.dev +SMTP_PASSWORD=0000 +SMTP_FROM=qsalesplatform@qcells.com \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 73dbbf1..6a3c17f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,6 +18,7 @@ "mssql": "^11.0.1", "mysql2": "^3.14.1", "next": "15.2.4", + "nodemailer": "^7.0.3", "react": "^19.0.0", "react-dom": "^19.0.0", "react-to-pdf": "^2.0.0", @@ -3700,6 +3701,15 @@ "license": "MIT", "optional": true }, + "node_modules/nodemailer": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-7.0.3.tgz", + "integrity": "sha512-Ajq6Sz1x7cIK3pN6KesGTah+1gnwMnx5gKl3piQlQQE/PwyJ4Mbc8is2psWYxK3RJTVeqsDaCv8ZzXLCDHMTZw==", + "license": "MIT-0", + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/open": { "version": "10.1.0", "resolved": "https://registry.npmjs.org/open/-/open-10.1.0.tgz", diff --git a/package.json b/package.json index 53ed0e8..5b0953b 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "@prisma/client": "^6.7.0", "@tanstack/react-query": "^5.71.0", "@tanstack/react-query-devtools": "^5.71.0", + "@types/nodemailer": "^6.4.17", "axios": "^1.8.4", "env-cmd": "^10.1.0", "iron-session": "^8.0.4", @@ -25,6 +26,7 @@ "mssql": "^11.0.1", "mysql2": "^3.14.1", "next": "15.2.4", + "nodemailer": "^7.0.3", "react": "^19.0.0", "react-dom": "^19.0.0", "react-to-pdf": "^2.0.0", diff --git a/src/libs/mailer.ts b/src/libs/mailer.ts new file mode 100644 index 0000000..a3f06e7 --- /dev/null +++ b/src/libs/mailer.ts @@ -0,0 +1,47 @@ +import nodemailer from 'nodemailer' + +interface EmailParams { + to: string | string[] + cc?: string | string[] + subject: string + content: string +} + +export async function sendEmail({ to, cc, subject, content }: EmailParams): Promise { + // Create a transporter using SMTP + const transporter = nodemailer.createTransport({ + host: process.env.SMTP_HOST, + port: Number(process.env.SMTP_PORT), + secure: process.env.SMTP_SECURE === 'true', + auth: { + user: process.env.SMTP_USER, + pass: process.env.SMTP_PASSWORD, + }, + }) + + // Email options + const mailOptions = { + from: process.env.SMTP_USER, + to: Array.isArray(to) ? to.join(', ') : to, + cc: cc ? (Array.isArray(cc) ? cc.join(', ') : cc) : undefined, + subject, + html: content, + } + + try { + // Send email + await transporter.sendMail(mailOptions) + } catch (error) { + console.error('Error sending email:', error) + throw new Error('Failed to send email') + } +} + +async function sendEmailTest() { + await sendEmail({ + to: 'test@test.com', + cc: 'test2@test.com', + subject: 'Test Email', + content: '

Hello

This is a test email.

', + }) +}