11import { render } from "@react-email/render" ;
2+ import nodemailer from "nodemailer" ;
23import { EmailError , MailMessage , MailTransport , PlainTextMailMessage } from "./index" ;
3- import nodemailer from "nodemailer"
44
55export type SmtpMailTransportOptions = {
6- type : ' smtp' ,
6+ type : " smtp" ;
77 config : {
8- host ?: string ,
9- port ?: number ,
10- secure ?: boolean ,
8+ host ?: string ;
9+ port ?: number ;
10+ secure ?: boolean ;
1111 auth ?: {
12- user ?: string ,
13- pass ?: string
14- }
15- }
16- }
12+ user ?: string ;
13+ pass ?: string ;
14+ } ;
15+ } ;
16+ } ;
1717
1818export class SmtpMailTransport implements MailTransport {
1919 #client: nodemailer . Transporter ;
2020
2121 constructor ( options : SmtpMailTransportOptions ) {
22- this . #client = nodemailer . createTransport ( options . config )
22+ this . #client = nodemailer . createTransport ( options . config ) ;
2323 }
2424
25- async send ( { to, from, replyTo, subject, react} : MailMessage ) : Promise < void > {
25+ async send ( { to, from, replyTo, subject, react } : MailMessage ) : Promise < void > {
2626 try {
2727 await this . #client. sendMail ( {
2828 from : from ,
@@ -31,16 +31,19 @@ export class SmtpMailTransport implements MailTransport {
3131 subject,
3232 html : render ( react ) ,
3333 } ) ;
34- }
35- catch ( error : Error ) {
36- console . error (
37- `Failed to send email to ${ to } , ${ subject } . Error ${ error . name } : ${ error . message } `
38- ) ;
39- throw new EmailError ( error ) ;
34+ } catch ( error ) {
35+ if ( error instanceof Error ) {
36+ console . error (
37+ `Failed to send email to ${ to } , ${ subject } . Error ${ error . name } : ${ error . message } `
38+ ) ;
39+ throw new EmailError ( error ) ;
40+ } else {
41+ throw error ;
42+ }
4043 }
4144 }
4245
43- async sendPlainText ( { to, from, replyTo, subject, text} : PlainTextMailMessage ) : Promise < void > {
46+ async sendPlainText ( { to, from, replyTo, subject, text } : PlainTextMailMessage ) : Promise < void > {
4447 try {
4548 await this . #client. sendMail ( {
4649 from : from ,
@@ -49,12 +52,15 @@ export class SmtpMailTransport implements MailTransport {
4952 subject,
5053 text : text ,
5154 } ) ;
52- }
53- catch ( error : Error ) {
54- console . error (
55- `Failed to send email to ${ to } , ${ subject } . Error ${ error . name } : ${ error . message } `
56- ) ;
57- throw new EmailError ( error ) ;
55+ } catch ( error ) {
56+ if ( error instanceof Error ) {
57+ console . error (
58+ `Failed to send email to ${ to } , ${ subject } . Error ${ error . name } : ${ error . message } `
59+ ) ;
60+ throw new EmailError ( error ) ;
61+ } else {
62+ throw error ;
63+ }
5864 }
5965 }
6066}
0 commit comments