Created
January 16, 2021 16:22
-
-
Save rafagsiqueira/e045f1a4ce2589d628886a4b52a49331 to your computer and use it in GitHub Desktop.
Example of sending emails using nodemailer and observable stream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import nodemailer from 'nodemailer'; | |
export class Emailer { | |
transporter: nodemailer.Transporter; | |
constructor() { | |
this.transporter = nodemailer.createTransport({ | |
host: 'mysmtpserver.com.br', | |
port: 25 | |
}); | |
} | |
sendEmail$ = (email: string): Observable<any> => { | |
const htmlString = '<html><body>This is an html email message <img src="cid:mail_header" alt="Letterhead of the Organization" /></body></html>'; | |
const message = { | |
envelope: { | |
to: email, | |
from: '[email protected]' | |
}, | |
subject: 'Message subject', | |
html: content, | |
attachments: [{ | |
filename: 'mail_header.gif', | |
path: './assets/mail_header.gif', | |
cid: 'mail_header' | |
}] | |
}; | |
return from(this.transporter.sendMail(message)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment