-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest-email-send.js
More file actions
55 lines (48 loc) · 1.84 KB
/
test-email-send.js
File metadata and controls
55 lines (48 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Test email sending
require('dotenv').config();
const nodemailer = require('nodemailer');
console.log('=== Email Sending Test ===\n');
// Create transporter
const transporter = nodemailer.createTransport({
service: process.env.EMAIL_SERVICE || 'gmail',
auth: {
user: process.env.EMAIL_USER,
pass: process.env.EMAIL_PASS
}
});
// Test email options
const mailOptions = {
from: process.env.EMAIL_FROM || process.env.EMAIL_USER,
to: process.env.EMAIL_USER, // Send to yourself for testing
subject: 'Campus Bridge - Test Email',
text: 'This is a test email from Campus Bridge LMS to confirm email functionality is working.',
html: `
<div style="font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto;">
<h2 style="color: #4CAF50;">Email Test Successful!</h2>
<p>This is a test email from Campus Bridge LMS to confirm email functionality is working.</p>
<p>If you received this email, your email configuration is correct.</p>
<br>
<p>Best regards,<br>Campus Bridge Team</p>
</div>
`
};
console.log('Sending test email to:', process.env.EMAIL_USER);
// Send email
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.log('ERROR: Failed to send email -', error.message);
// Common error handling
if (error.message.includes('Invalid login')) {
console.log('POSSIBLE FIX: Check Gmail App Password');
} else if (error.message.includes('authentication')) {
console.log('POSSIBLE FIX: Check email credentials');
} else if (error.message.includes('limit')) {
console.log('POSSIBLE FIX: Gmail daily sending limit reached');
}
} else {
console.log('SUCCESS: Email sent successfully');
console.log('Message ID:', info.messageId);
console.log('Response:', info.response);
}
console.log('\n=== Email Sending Test Complete ===');
});