To enable real email sending functionality, follow these steps:
-
Enable 2-Factor Authentication
- Go to your Google Account settings
- Click on "Security" in the left sidebar
- Under "Signing in to Google," click on "2-Step Verification"
- Follow the prompts to set up 2FA
-
Generate an App Password
- In the same "Security" section, scroll down to "App passwords"
- If you can't see this option, make sure 2FA is enabled
- Click on "App passwords"
- Select "Mail" as the app
- Select "Other (Custom name)" and type "Campus Bridge"
- Click "Generate"
- Copy the 16-character password (without spaces)
Replace the placeholder values in your .env file with your actual credentials:
# Email Configuration
# For Gmail, you need to generate an App Password: https://myaccount.google.com/apppasswords
EMAIL_SERVICE=gmail
EMAIL_USER=your-actual-gmail-address@gmail.com
EMAIL_PASS=your-16-character-app-password
EMAIL_FROM=your-actual-gmail-address@gmail.comExample with real values:
# Email Configuration
# For Gmail, you need to generate an App Password: https://myaccount.google.com/apppasswords
EMAIL_SERVICE=gmail
EMAIL_USER=john.doe@gmail.com
EMAIL_PASS=abcd1234efgh5678
EMAIL_FROM=john.doe@gmail.comAfter updating your .env file:
-
Save the file
-
Run the test script:
cd /Users/madanthambisetty/Downloads/Campus-Bridge node test-email-config.js -
Check your email for a test message
After confirming the email configuration works:
- Stop your server (Ctrl+C)
- Start your server again:
or
npm start
node server.js
If you prefer not to use Gmail, you can configure other email services:
EMAIL_SERVICE=hotmail
EMAIL_USER=your-email@outlook.com
EMAIL_PASS=your-password
EMAIL_FROM=your-email@outlook.comEMAIL_SERVICE=yahoo
EMAIL_USER=your-email@yahoo.com
EMAIL_PASS=your-password
EMAIL_FROM=your-email@yahoo.comIf you encounter issues:
-
"Username and Password not accepted" Error
- Make sure you're using an App Password, not your regular Gmail password
- Ensure 2FA is enabled
- Double-check the App Password was generated for "Mail"
-
Connection Timeout Errors
- Check your internet connection
- Verify firewall settings aren't blocking the connection
-
Authentication Errors
- Verify all environment variables are correctly set
- Check for typos in your email address or password
- Never commit your .env file to version control
- The .env file is already in .gitignore to prevent accidental commits
- Use App Passwords instead of regular passwords for better security
- Store your .env file securely
Once configured correctly:
- Users requesting password resets will receive actual emails
- The fallback mechanism (showing reset links directly) will only be used if email fails
- All other email features (registration confirmation, login confirmation) will work
If you continue to have issues:
- Double-check all values in your .env file
- Verify your App Password was generated correctly
- Ensure 2FA is enabled on your Google account
- Run the test script to verify configuration