1
1
import { createTransport } from "nodemailer" ;
2
2
3
- const { sendMail } = createTransport ( {
3
+ const transport = createTransport ( {
4
4
host : process . env . SMTP_HOST ,
5
5
port : parseInt ( process . env . SMTP_PORT ! ) ,
6
6
secure : parseInt ( process . env . SMTP_PORT ! ) == 465 ,
7
7
auth : {
8
8
type : "oauth2" ,
9
9
user : process . env . SMTP_USER ,
10
- refreshToken : process . env . SMTP_REFRESH_TOKEN
11
- }
10
+ refreshToken : process . env . SMTP_REFRESH_TOKEN ,
11
+ clientId : process . env . SMTP_CLI_ID ,
12
+ clientSecret : process . env . SMTP_CLI_SEC
13
+ } ,
14
+ requireTLS : true
12
15
} )
13
16
14
- const registrationEmailHtml = ( username : string ) => `
15
- <!DOCTYPE html>
16
- <html lang="en">
17
- <head>
18
- <meta charset="UTF-8">
19
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
20
- <style>
21
- body {
22
- font-family: Arial, sans-serif;
23
- line-height: 1.6;
24
- color: #333;
25
- }
26
- .container {
27
- max-width: 600px;
28
- margin: 0 auto;
29
- padding: 20px;
30
- background-color: #f7f7f7;
31
- border-radius: 8px;
32
- box-shadow: 0 2px 4px rgba(0,0,0,0.1);
33
- }
34
- .header {
35
- text-align: center;
36
- padding-bottom: 20px;
37
- border-bottom: 1px solid #eaeaea;
38
- }
39
- .content {
40
- margin-top: 20px;
41
- }
42
- .footer {
43
- margin-top: 30px;
44
- text-align: center;
45
- font-size: 12px;
46
- color: #999;
47
- }
48
- </style>
49
- </head>
50
- <body>
51
- <div class="container">
52
- <div class="header">
53
- <h1>Thank You for Registering, ${ username } !</h1>
54
- </div>
55
- <div class="content">
56
- <p>Dear ${ username } ,</p>
57
- <p>We're thrilled to have you on board. Thank you for registering with us!</p>
58
- <p>We hope you enjoy your experience. If you have any questions, feel free to reach out.</p>
59
- </div>
60
- <div class="footer">
61
- <p>© ${ new Date ( ) . getFullYear ( ) } Dev.Calender. All rights reserved.</p>
62
- </div>
63
- </div>
64
- </body>
65
- </html>
66
- ` ;
67
-
68
- export const sendRegMail = async ( email : string , username : string ) => {
69
- await sendMail ( {
70
- from : process . env . SMTP_USER ,
71
- to : email ,
72
- subject : "Registration Confirmation" ,
73
- html : registrationEmailHtml ( username )
74
- } )
17
+ export const sendRegMail = async ( email , username ) => transport . sendMail ( {
18
+ from : process . env . SMTP_USER ,
19
+ to : email ,
20
+ subject : "Registration Confirmation" ,
21
+ html : `
22
+ <!DOCTYPE html>
23
+ <html lang="en">
24
+ <head>
25
+ <meta charset="UTF-8">
26
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
27
+ <style>
28
+ body {
29
+ font-family: Arial, sans-serif;
30
+ line-height: 1.6;
31
+ color: #333;
75
32
}
33
+ .container {
34
+ max-width: 600px;
35
+ margin: 0 auto;
36
+ padding: 20px;
37
+ background-color: #f7f7f7;
38
+ border-radius: 8px;
39
+ box-shadow: 0 2px 4px rgba(0,0,0,0.1);
40
+ }
41
+ .header {
42
+ text-align: center;
43
+ padding-bottom: 20px;
44
+ border-bottom: 1px solid #eaeaea;
45
+ }
46
+ .content {
47
+ margin-top: 20px;
48
+ }
49
+ .footer {
50
+ margin-top: 30px;
51
+ text-align: center;
52
+ font-size: 12px;
53
+ color: #999;
54
+ }
55
+ </style>
56
+ </head>
57
+ <body>
58
+ <div class="container">
59
+ <div class="header">
60
+ <h1>Thank You for Registering, ${ username } !</h1>
61
+ </div>
62
+ <div class="content">
63
+ <p>Dear ${ username } ,</p>
64
+ <p>We're thrilled to have you on board. Thank you for registering with us!</p>
65
+ <p>We hope you enjoy your experience. If you have any questions, feel free to reach out.</p>
66
+ </div>
67
+ <div class="footer">
68
+ <p>© ${ new Date ( ) . getFullYear ( ) } Dev.Calender. All rights reserved.</p>
69
+ </div>
70
+ </div>
71
+ </body>
72
+ </html>
73
+ `
74
+ } , ( err , info ) => {
75
+ if ( err ) {
76
+ console . error ( err ) ;
77
+ }
78
+ console . log ( info . response ) ;
79
+ } )
76
80
77
- const loginEmailHtml = ( username : string ) => `
78
- <!DOCTYPE html>
79
- <html lang="en">
80
- <head>
81
- <meta charset="UTF-8">
82
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
83
- <style>
84
- body {
85
- font-family: Arial, sans-serif;
86
- line-height: 1.6;
87
- color: #333;
88
- }
89
- .container {
90
- max-width: 600px;
91
- margin: 0 auto;
92
- padding: 20px;
93
- background-color: #f7f7f7;
94
- border-radius: 8px;
95
- box-shadow: 0 2px 4px rgba(0,0,0,0.1);
96
- }
97
- .header {
98
- text-align: center;
99
- padding-bottom: 20px;
100
- border-bottom: 1px solid #eaeaea;
101
- }
102
- .content {
103
- margin-top: 20px;
104
- }
105
- .footer {
106
- margin-top: 30px;
107
- text-align: center;
108
- font-size: 12px;
109
- color: #999;
110
- }
111
- </style>
112
- </head>
113
- <body>
114
- <div class="container">
115
- <div class="header">
116
- <h1>New login from ${ username } !</h1>
117
- </div>
118
- <div class="content">
119
- <p>Dear ${ username } ,</p>
120
- <p>This is an automated email to let you know that we have a new login from your account.</p>
121
- <p>If you think someone else accessed your account, please contact support.</p>
122
- </div>
123
- <div class="footer">
124
- <p>© ${ new Date ( ) . getFullYear ( ) } Dev.Calender. All rights reserved.</p>
125
- </div>
126
- </div>
127
- </body>
128
- </html>
129
- ` ;
130
-
131
- export const sendLoginMail = async ( email : string , username : string ) => {
132
- await sendMail ( {
133
- from : process . env . SMTP_USER ,
134
- to : email ,
135
- subject : "New login from your account" ,
136
- html : loginEmailHtml ( username )
137
- } )
81
+ export const sendLoginMail = async ( email , username ) => transport . sendMail ( {
82
+ from : process . env . SMTP_USER ,
83
+ to : email ,
84
+ subject : "New login from your account" ,
85
+ html : `
86
+ <!DOCTYPE html>
87
+ <html lang="en">
88
+ <head>
89
+ <meta charset="UTF-8">
90
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
91
+ <style>
92
+ body {
93
+ font-family: Arial, sans-serif;
94
+ line-height: 1.6;
95
+ color: #333;
138
96
}
139
- export default sendMail
97
+ .container {
98
+ max-width: 600px;
99
+ margin: 0 auto;
100
+ padding: 20px;
101
+ background-color: #f7f7f7;
102
+ border-radius: 8px;
103
+ box-shadow: 0 2px 4px rgba(0,0,0,0.1);
104
+ }
105
+ .header {
106
+ text-align: center;
107
+ padding-bottom: 20px;
108
+ border-bottom: 1px solid #eaeaea;
109
+ }
110
+ .content {
111
+ margin-top: 20px;
112
+ }
113
+ .footer {
114
+ margin-top: 30px;
115
+ text-align: center;
116
+ font-size: 12px;
117
+ color: #999;
118
+ }
119
+ </style>
120
+ </head>
121
+ <body>
122
+ <div class="container">
123
+ <div class="header">
124
+ <h1>New login from ${ username } !</h1>
125
+ </div>
126
+ <div class="content">
127
+ <p>Dear ${ username } ,</p>
128
+ <p>This is an automated email to let you know that we have a new login from your account.</p>
129
+ <p>If you think someone else accessed your account, please contact support.</p>
130
+ </div>
131
+ <div class="footer">
132
+ <p>© ${ new Date ( ) . getFullYear ( ) } Dev.Calender. All rights reserved.</p>
133
+ </div>
134
+ </div>
135
+ </body>
136
+ </html>
137
+ `
138
+ } , ( err , info ) => {
139
+ if ( err ) {
140
+ console . error ( err ) ;
141
+ }
142
+ console . log ( info . response ) ;
143
+ } )
144
+
145
+ export default transport . sendMail
0 commit comments