This guide will help you properly configure email functionality for password resets and other email features in Campus Bridge.
Your application currently has email functionality implemented but is using placeholder values in the .env file:
EMAIL_SERVICE=gmail
EMAIL_USER=youremail@gmail.com
EMAIL_PASS=your_app_password
EMAIL_FROM=youremail@gmail.comEven with placeholder values, the password reset functionality still works:
- When a user requests a password reset, the system generates a reset token
- Since email is not properly configured, the system displays the reset link directly
- Users can click this link to reset their password without receiving an email
This ensures functionality is always available, even when email is not configured.
To enable actual email sending, follow these steps:
If you're using Gmail:
-
Enable 2-Factor Authentication
- Go to your Google Account settings
- Navigate to Security > 2-Step Verification
- Turn on 2-Step Verification
-
Generate an App Password
- In the same Security section, scroll down to "App passwords"
- Generate a new app password for "Mail"
- Copy the 16-character password (no spaces)
Replace the placeholder values with your actual credentials:
EMAIL_SERVICE=gmail
EMAIL_USER=youractualgmailaddress@gmail.com
EMAIL_PASS=th1s1s4n4ppp4ssw0rd
EMAIL_FROM=youractualgmailaddress@gmail.comImportant notes:
- Use your actual Gmail address (not the placeholder)
- Use the App Password (not your regular Gmail password)
- The EMAIL_FROM should typically be the same as EMAIL_USER
After updating the .env file:
- Stop your server (Ctrl+C)
- Start your server again (
npm startornode server.js)
To test if your email configuration is working:
-
Run the test script:
node test-email.js
-
Check your email for a test message
This is the most common error and usually means:
-
Using regular password instead of App Password
- Solution: Generate and use an App Password
-
2-Factor Authentication not enabled
- Solution: Enable 2FA on your Google account
-
Incorrect App Password
- Solution: Generate a new App Password
-
Check credentials
- Verify EMAIL_USER is your complete Gmail address
- Verify EMAIL_PASS is the App Password (16 characters)
-
Gmail security settings
- Less secure app access may need to be enabled (though not recommended)
- Consider using a dedicated email service for production
You can use other email services by changing the EMAIL_SERVICE value:
# For Outlook/Hotmail
EMAIL_SERVICE=hotmail
EMAIL_USER=youraddress@outlook.com
EMAIL_PASS=yourpassword
EMAIL_FROM=youraddress@outlook.com
# For Yahoo
EMAIL_SERVICE=yahoo
EMAIL_USER=youraddress@yahoo.com
EMAIL_PASS=yourpassword
EMAIL_FROM=youraddress@yahoo.com-
Never commit .env files to version control
- The .env file is already in .gitignore
-
Use App Passwords
- More secure than regular passwords
- Can be revoked without changing your main password
-
Environment-specific configurations
- Use different .env files for development, staging, and production
- User requests password reset on forgot-password.html
- Server generates secure token and expiration (1 hour)
- If email configured: sends email with reset link
- If email not configured: displays reset link directly
- User clicks link to access reset-password.html
- User enters new password
- Server validates token and updates password
- Token is cleared after successful reset
If you continue to have issues:
- Double-check all values in .env file
- Verify App Password was generated correctly
- Ensure 2FA is enabled
- Test with the test-email.js script