2025-10-05 08:45:39 +00:00
|
|
|
import { google } from "googleapis";
|
2025-10-11 10:32:52 +00:00
|
|
|
import nodemailer from "nodemailer";
|
2025-10-05 08:45:39 +00:00
|
|
|
import { config } from "./config.js";
|
2025-10-11 10:32:52 +00:00
|
|
|
|
2025-10-05 08:45:39 +00:00
|
|
|
const OAuth2 = google.auth.OAuth2;
|
|
|
|
|
|
2025-10-15 14:30:36 +00:00
|
|
|
export const createTransporter = () => {
|
2025-10-05 08:45:39 +00:00
|
|
|
const oauth2Client = new OAuth2(
|
|
|
|
|
config.EMAIL_CLIENT_ID,
|
|
|
|
|
config.EMAIL_CLIENT_SECRET,
|
|
|
|
|
"https://developers.google.com/oauthplayground"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
oauth2Client.setCredentials({
|
|
|
|
|
refresh_token: config.EMAIL_REFRESH_TOKEN,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const transporter = nodemailer.createTransport({
|
|
|
|
|
host: "smtp.gmail.com",
|
|
|
|
|
port: 465,
|
|
|
|
|
secure: true,
|
|
|
|
|
auth: {
|
|
|
|
|
type: "OAuth2",
|
|
|
|
|
user: config.EMAIL_USER,
|
|
|
|
|
clientId: config.EMAIL_CLIENT_ID,
|
|
|
|
|
clientSecret: config.EMAIL_CLIENT_SECRET,
|
|
|
|
|
refreshToken: config.EMAIL_REFRESH_TOKEN,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return transporter;
|
|
|
|
|
};
|
|
|
|
|
|
2025-10-15 14:30:36 +00:00
|
|
|
export const transporter = createTransporter();
|