Skip to content

Email Service

Manvendra Bhardwaj edited this page Jun 14, 2026 · 1 revision

Email Service

Overview

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.


Features

  • Gmail OAuth2 Authentication

  • Secure email delivery

  • HTML and Plain Text support

  • Registration welcome emails

  • Environment variable configuration

  • Connection verification on startup


Architecture

User Registration
        │
        ▼
AI Debugger Assistant
        │
        ▼
Email Service (Nodemailer)
        │
        ▼
Google OAuth2
        │
        ▼
Gmail SMTP Server
        │
        ▼
Recipient Inbox

Environment Variables

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


Email Transport Configuration

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,
},
});

Connection Verification

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.


Sending Emails

The sendEmail() helper function is responsible for sending emails.

Parameters

Parameter Description
to Recipient email address
subject Email subject
text Plain text content
html HTML email content

Example

await sendEmail(
  "user@example.com",
  "Welcome",
  "Welcome to AI Debugger Assistant",
  "<h1>Welcome</h1>"
);

Registration Email Workflow

When a user successfully registers:

  1. Registration is completed.

  2. User details are stored.

  3. sendRegistrationEmail() is executed.

  4. A welcome email is delivered.

Workflow

User Signup
      │
      ▼
Account Created
      │
      ▼
sendRegistrationEmail()
      │
      ▼
sendEmail()
      │
      ▼
Gmail OAuth2
      │
      ▼
User Receives Welcome Email

Welcome Email Template

Subject

Welcome to AI Debugger Assistant

Email Content

<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>


Security Considerations

OAuth2 Authentication

OAuth2 eliminates the need to store Gmail passwords directly.

Environment Variables

Store all credentials in environment variables.

Never commit:

CLIENT_SECRET
REFRESH_TOKEN
EMAIL_USER

to a public repository.

Git Ignore

.env

Error Handling

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


Future Enhancements

  • Password reset emails

  • Email verification system

  • Bug report delivery

  • Debug analysis reports

  • Admin alert notifications

  • Email templates using Handlebars

  • Queue-based email processing


Related Pages

  • Authentication

  • User Management

  • API Reference

  • Deployment

  • Security

Clone this wiki locally