Repository navigation
Email Service
The Email Service module enables AI Debugger Assistant to send transactional emails using Nodemailer with Google OAuth2 Authentication.
This service is responsible for:
User registration emails
Welcome messages
Account notifications
Future password reset emails
Security and verification emails
Instead of storing an email password, OAuth2 is used to provide secure access to Gmail.
Gmail OAuth2 Authentication
Secure email delivery
HTML and Plain Text support
Registration welcome emails
Environment variable configuration
Connection verification on startup
User Registration
│
▼
AI Debugger Assistant
│
▼
Email Service (Nodemailer)
│
▼
Google OAuth2
│
▼
Gmail SMTP Server
│
▼
Recipient Inbox
Create a .env file and configure the following variables:
EMAIL_USER=your-email@gmail.com
CLIENT_ID=your-google-client-id
CLIENT_SECRET=your-google-client-secret
REFRESH_TOKEN=your-google-refresh-token
The service uses Gmail with OAuth2 authentication.
const transporter = nodemailer.createTransport({
service: "gmail",
auth: {
type: "OAuth2",
user: process.env.EMAIL_USER,
clientId: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
refreshToken: process.env.REFRESH_TOKEN,
},
});
Before sending emails, the transporter verifies the connection.
transporter.verify((error, success) => {
if (error) {
console.error(error);
} else {
console.log("Email server is ready");
}
});
This ensures that OAuth credentials are valid and Gmail is reachable.
The sendEmail() helper function is responsible for sending emails.
| Parameter | Description |
|---|---|
| to | Recipient email address |
| subject | Email subject |
| text | Plain text content |
| html | HTML email content |
await sendEmail(
"user@example.com",
"Welcome",
"Welcome to AI Debugger Assistant",
"<h1>Welcome</h1>"
);
When a user successfully registers:
Registration is completed.
User details are stored.
sendRegistrationEmail()is executed.A welcome email is delivered.
User Signup
│
▼
Account Created
│
▼
sendRegistrationEmail()
│
▼
sendEmail()
│
▼
Gmail OAuth2
│
▼
User Receives Welcome Email
Welcome to AI Debugger Assistant
<p>Hello User,</p>
<p>
Thank you for registering at AI Debugger Assistant.
We're excited to have you on board!
</p>
<p>
Best Regards,<br>
The AI Team
</p>
OAuth2 eliminates the need to store Gmail passwords directly.
Store all credentials in environment variables.
Never commit:
CLIENT_SECRET
REFRESH_TOKEN
EMAIL_USER
to a public repository.
.env
Email delivery errors are captured and logged.
catch(error){
console.error("Error sending email:", error);
}
This helps diagnose:
Invalid OAuth credentials
Gmail authentication failures
Network issues
Expired refresh tokens
Password reset emails
Email verification system
Bug report delivery
Debug analysis reports
Admin alert notifications
Email templates using Handlebars
Queue-based email processing
Authentication
User Management
API Reference
Deployment
Security