@studiosonrai/nestjs-email
v1.1.0
Published
Email module for NestJS applications with Azure Communication Service, SMTP, and Resend support
Downloads
232
Readme
@studiosonrai/nestjs-email
Email module for NestJS with SMTP, Azure Communication Service, and Resend support.
Installation
npm install @studiosonrai/nestjs-email
# For SMTP:
npm install nodemailer
# For Azure:
npm install @azure/communication-email
# For Resend:
npm install resendUsage
SMTP
import { EmailModule, EmailService } from '@studiosonrai/nestjs-email';
@Module({
imports: [
EmailModule.forRootAsync({
inject: [ConfigService],
useFactory: (config: ConfigService) => ({
provider: 'smtp',
smtp: {
host: config.get('SMTP_HOST'),
port: config.get('SMTP_PORT'),
auth: { user: config.get('SMTP_USER'), pass: config.get('SMTP_PASS') },
},
defaultFrom: config.get('MAIL_FROM'),
}),
}),
],
})
export class AppModule {}Resend
@Module({
imports: [
EmailModule.forRootAsync({
inject: [ConfigService],
useFactory: (config: ConfigService) => ({
provider: 'resend',
resend: {
apiKey: config.get('RESEND_API_KEY'),
},
defaultFrom: config.get('MAIL_FROM'),
}),
}),
],
})
export class AppModule {}Sending Emails
// Inject and use
@Injectable()
export class MyService {
constructor(private emailService: EmailService) {}
async send() {
await this.emailService.sendEmail('[email protected]', 'Subject', '<p>Body</p>');
}
}Configuration
| Option | Type | Description |
|--------|------|-------------|
| provider | 'smtp' \| 'azure' \| 'resend' | Email provider |
| smtp | { host, port, secure?, auth? } | SMTP config |
| azure | { connectionString, senderAddress } | Azure config |
| resend | { apiKey } | Resend config |
| defaultFrom | string | Default sender address |
| imageCompression | { enabled, maxWidth?, quality? } | Compress inline images |
| verbose | boolean | Enable logging |
