@zola_do/email 0.2.7 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -19
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -49,8 +49,8 @@ EMAIL_SMTP_DISPLAY_NAME=My App <noreply@example.com>
|
|
|
49
49
|
### 2. Register Module
|
|
50
50
|
|
|
51
51
|
```typescript
|
|
52
|
-
import { Module } from
|
|
53
|
-
import { EmailModule } from
|
|
52
|
+
import { Module } from '@nestjs/common';
|
|
53
|
+
import { EmailModule } from '@zola_do/email';
|
|
54
54
|
|
|
55
55
|
@Module({
|
|
56
56
|
imports: [EmailModule],
|
|
@@ -61,8 +61,8 @@ export class AppModule {}
|
|
|
61
61
|
### 3. Send Emails
|
|
62
62
|
|
|
63
63
|
```typescript
|
|
64
|
-
import { Injectable } from
|
|
65
|
-
import { EmailService } from
|
|
64
|
+
import { Injectable } from '@nestjs/common';
|
|
65
|
+
import { EmailService } from '@zola_do/email';
|
|
66
66
|
|
|
67
67
|
@Injectable()
|
|
68
68
|
export class NotificationService {
|
|
@@ -71,7 +71,7 @@ export class NotificationService {
|
|
|
71
71
|
async sendWelcomeEmail(userEmail: string, userName: string) {
|
|
72
72
|
await this.emailService.sendEmail({
|
|
73
73
|
to: userEmail,
|
|
74
|
-
subject:
|
|
74
|
+
subject: 'Welcome to Our App',
|
|
75
75
|
html: `
|
|
76
76
|
<h1>Welcome, ${userName}!</h1>
|
|
77
77
|
<p>Thanks for signing up.</p>
|
|
@@ -141,8 +141,8 @@ async sendEmail(options: {
|
|
|
141
141
|
### Send with Template
|
|
142
142
|
|
|
143
143
|
```typescript
|
|
144
|
-
import { MailerService } from
|
|
145
|
-
import { context } from
|
|
144
|
+
import { MailerService } from '@nestjs-modules/mailer';
|
|
145
|
+
import { context } from '@handlebars/noder';
|
|
146
146
|
|
|
147
147
|
@Injectable()
|
|
148
148
|
export class NotificationService {
|
|
@@ -154,8 +154,8 @@ export class NotificationService {
|
|
|
154
154
|
async sendWelcomeWithTemplate(user: User) {
|
|
155
155
|
await this.mailerService.sendMail({
|
|
156
156
|
to: user.email,
|
|
157
|
-
subject:
|
|
158
|
-
template:
|
|
157
|
+
subject: 'Welcome!',
|
|
158
|
+
template: 'welcome', // Looks for templates/welcome.hbs
|
|
159
159
|
context: {
|
|
160
160
|
name: user.name,
|
|
161
161
|
verifyUrl: `https://example.com/verify/${user.token}`,
|
|
@@ -200,7 +200,7 @@ project/
|
|
|
200
200
|
|
|
201
201
|
<html>
|
|
202
202
|
<head>
|
|
203
|
-
<meta charset=
|
|
203
|
+
<meta charset='utf-8' />
|
|
204
204
|
<title>Welcome</title>
|
|
205
205
|
<style>
|
|
206
206
|
body {
|
|
@@ -213,10 +213,10 @@ project/
|
|
|
213
213
|
</style>
|
|
214
214
|
</head>
|
|
215
215
|
<body>
|
|
216
|
-
<div class=
|
|
216
|
+
<div class='container'>
|
|
217
217
|
<h1>Welcome, {{name}}!</h1>
|
|
218
218
|
<p>Thank you for joining {{appName}}.</p>
|
|
219
|
-
<a href=
|
|
219
|
+
<a href='{{verifyUrl}}'>Verify your email</a>
|
|
220
220
|
<p>Best,<br />The Team</p>
|
|
221
221
|
</div>
|
|
222
222
|
</body>
|
|
@@ -279,26 +279,26 @@ project/
|
|
|
279
279
|
### Custom Configuration
|
|
280
280
|
|
|
281
281
|
```typescript
|
|
282
|
-
import { Module } from
|
|
283
|
-
import { EmailModule, EmailConfig } from
|
|
282
|
+
import { Module } from '@nestjs/common';
|
|
283
|
+
import { EmailModule, EmailConfig } from '@zola_do/email';
|
|
284
284
|
|
|
285
285
|
@Module({
|
|
286
286
|
imports: [
|
|
287
287
|
EmailModule.forRoot({
|
|
288
288
|
transport: {
|
|
289
|
-
host:
|
|
289
|
+
host: 'smtp.gmail.com',
|
|
290
290
|
port: 465,
|
|
291
291
|
secure: true,
|
|
292
292
|
auth: {
|
|
293
|
-
user:
|
|
294
|
-
pass:
|
|
293
|
+
user: 'your-email@gmail.com',
|
|
294
|
+
pass: 'your-app-password',
|
|
295
295
|
},
|
|
296
296
|
},
|
|
297
297
|
defaults: {
|
|
298
298
|
from: '"My App" <noreply@myapp.com>',
|
|
299
299
|
},
|
|
300
300
|
template: {
|
|
301
|
-
dir: __dirname +
|
|
301
|
+
dir: __dirname + '/templates',
|
|
302
302
|
adapter: new HandlebarsAdapter(),
|
|
303
303
|
},
|
|
304
304
|
} as EmailConfig),
|
|
@@ -439,7 +439,7 @@ Ensure templates are in `process.cwd() + '/templates/'`:
|
|
|
439
439
|
|
|
440
440
|
```typescript
|
|
441
441
|
// Check template path
|
|
442
|
-
console.log(process.cwd() +
|
|
442
|
+
console.log(process.cwd() + '/templates/');
|
|
443
443
|
```
|
|
444
444
|
|
|
445
445
|
### Q: Handlebars syntax errors?
|