Repository navigation
Expand file tree
/
Copy pathmailer.js
More file actions
122 lines (101 loc) · 6 KB
/
Copy pathmailer.js
File metadata and controls
122 lines (101 loc) · 6 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
const nodemailer = require('nodemailer');
const transporter = nodemailer.createTransport({
host: process.env.SMTP_HOST || 'sandbox.smtp.mailtrap.io',
port: process.env.SMTP_PORT || 2525,
secure: false,
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASS
},
debug: false,
logger: false
});
async function sendEnrollmentConfirmation(to, studentName, courseName) {
try {
const info = await transporter.sendMail({
from: '"University of Vienna" <noreply@univienna.edu>',
to: to,
subject: 'Enrollment Confirmation',
text: `Hello ${studentName},\n\nYou have successfully enrolled in ${courseName}.\n\nBest regards,\nUniversity of Vienna`,
html: `
<div style="font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto;">
<div style="background: linear-gradient(135deg, #4e54c8, #8f94fb); color: white; padding: 20px; text-align: center;">
<h2>University of Vienna</h2>
<p>Enrollment Confirmation</p>
</div>
<div style="padding: 30px; background-color: #f9f9f9;">
<p>Hello <strong>${studentName}</strong>,</p>
<p>You have successfully enrolled in <strong>${courseName}</strong>.</p>
<p>Best regards,<br><br>University of Vienna</p>
</div>
</div>`
});
console.log('\nEnrollment email sent successfully to:', to);
return info;
} catch (error) {
console.error('\nError sending enrollment email:', error);
throw error;
}
}
async function sendStudentCredentials(to, studentName, tempPassword) {
try {
const info = await transporter.sendMail({
from: '"University of Vienna - Administration" <admin@univienna.edu>',
to: to,
subject: 'Your Student Account Has Been Created',
text: `Dear ${studentName},
Welcome to the University of Vienna Student Enrollment System!
Your student account has been successfully created by our administrative staff. Below are your login credentials:
Email: ${to}
Temporary Password: ${tempPassword}
IMPORTANT SECURITY NOTICE:
- This is a temporary password generated by our system
- Please log in and change your password immediately
- Keep your credentials secure and do not share them with anyone
You can access the system at: [University Login Portal]
If you have any questions or need assistance, please contact our student support team.
Best regards,
University of Vienna Administration`,
html: `
<div style="font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto;">
<div style="background: linear-gradient(135deg, #4e54c8, #8f94fb); color: white; padding: 20px; text-align: center;">
<h2>Welcome to University of Vienna</h2>
<p>Student Enrollment System</p>
</div>
<div style="padding: 30px; background-color: #f9f9f9;">
<h3>Dear ${studentName},</h3>
<p>Your student account has been successfully created by our administrative staff.</p>
<div style="background-color: white; border-left: 4px solid #4e54c8; padding: 20px; margin: 20px 0;">
<h4>Your Login Credentials:</h4>
<p><strong>Email:</strong> ${to}</p>
<p><strong>Temporary Password:</strong> <code style="background-color: #f0f0f0; padding: 2px 6px; border-radius: 3px;">${tempPassword}</code></p>
</div>
<div style="background-color: #fff3cd; border: 1px solid #ffeaa7; padding: 15px; border-radius: 5px; margin: 20px 0;">
<h4 style="color: #856404;">🔒 Important Security Notice:</h4>
<ul style="color: #856404; margin: 0;">
<li>This is a temporary password generated by our system</li>
<li>Please log in and change your password immediately</li>
<li>Keep your credentials secure and do not share them</li>
</ul>
</div>
<div style="text-align: center; margin: 30px 0;">
<a href="#" style="background-color: #4e54c8; color: white; padding: 12px 25px; text-decoration: none; border-radius: 5px; display: inline-block;">Access Student Portal</a>
</div>
<p>If you have any questions or need assistance, please contact our student support team.</p>
<p>Best regards,<br><br>
<strong>University of Vienna Administration</strong></p>
</div>
<div style="background-color: #e9ecef; padding: 15px; text-align: center; font-size: 12px; color: #6c757d;">
<p>This is an automated message. Please do not reply to this email.</p>
</div>
</div>`
});
console.log('\nStudent credentials email sent successfully to:', to);
return info;
} catch (error) {
console.error('\nError sending student credentials email:', error);
console.error('Error details:', error.message);
throw error;
}
}
module.exports = { sendEnrollmentConfirmation, sendStudentCredentials };