Skip to content

Instantly share code, notes, and snippets.

@rafagsiqueira
Created January 16, 2021 16:22
Show Gist options
  • Save rafagsiqueira/e045f1a4ce2589d628886a4b52a49331 to your computer and use it in GitHub Desktop.
Save rafagsiqueira/e045f1a4ce2589d628886a4b52a49331 to your computer and use it in GitHub Desktop.
Example of sending emails using nodemailer and observable stream
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