10 examples of 'npm nodemailer' in JavaScript

Every line of 'npm nodemailer' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
83function Nodemailer(options){
84 var mailcomposerOptions = {};
85
86 this.options = options || {};
87
88 this.transport = this.options.transport;
89
90 mailcomposerOptions.identityString = X_MAILER_NAME + " " + packageData.version;
91
92 if(this.options.identityString){
93 mailcomposerOptions.identityString = this.options.identityString;
94 }
95
96 if(this.options.encoding){
97 mailcomposerOptions.encoding = this.options.encoding;
98 }
99
100 if(this.options.charset){
101 mailcomposerOptions.charset = this.options.charset;
102 }
103
104 if(!!this.options.forceEmbeddedImages){
105 mailcomposerOptions.forceEmbeddedImages = true;
106 }
107
108 this.mailcomposer = new MailComposer(mailcomposerOptions);
109
110 if(!this.transport){
111 this.transport = this.getGlobalTransport();
112 }
113}
15protected get nodeMailer() {
16 if (!require) {
17 throw new Error("Cannot load nodemailer. Try to install all required dependencies.");
18 }
19 if (!this._nodeMailer) {
20 try {
21 this._nodeMailer = require("nodemailer");
22 } catch (e) {
23 throw new Error("nodemailer package was not found installed. Try to install it: npm install nodemailer --save");
24 }
25 }
26 return this._nodeMailer;
27}
16function _nodemailerServer()
17{
18 if (!_nodemailerTransport)
19 {
20 _nodemailerTransport = nodemailer.createTransport("SMTP",{
21 service: "Gmail",
22 auth: {
23 user: process.env.SMTP_USER + "@gmail.com",
24 pass: process.env.SMTP_PASSWORD
25 }
26 });
27 }
28
29 return _nodemailerTransport;
30}
60function sendMail(options, callback){
61 var mailer = new Nodemailer(options);
62 mailer.validateSettings(function(err){
63 if(err){
64 // report validation error back to the client
65 return callback(err);
66 }else{
67 // try to send the e-mail message
68 mailer.sendMail(callback);
69 }
70 });
71
72 return mailer;
73}
31async prepare() {
32 const transport = typeof this.config.transport === 'string'
33 // eslint-disable-next-line global-require
34 ? require(this.config.transport)
35 : this.config.transport
36 const instance = nodemailer.createTransport(
37 await transport(this.config.options),
38 this.config.defaults,
39 )
40
41 // Attach a child logger to the nodemailer transport
42 instance.logger = this.log.child({ transport: instance.transporter.name })
43
44 // Apply plugins
45 for (const definition of this.config.plugins || []) {
46 const plugin = typeof definition.plugin === 'string'
47 // eslint-disable-next-line global-require
48 ? require(definition.plugin)
49 : definition.plugin
50 instance.use(definition.event, plugin(definition.options))
51 }
52
53 // Attach a promisified version of the sendMail function
54 instance.send = instance::send
55
56 return Promise.resolve(instance)
57}
23constructor (logger, config, transportImpl) {
24 this.logger = logger;
25 this._transport = nodemailer.createTransport(transportImpl);
26 this._transport.use('compile', htmlToText());
27 this._send = Q.promisify(this._transport.sendMail, {
28 context: this._transport
29 });
30}
15function createSMTPClient(option) {
16 debug('createSMTPClient option', option);
17 if (!option) {
18 option = { // eslint-disable-line no-param-reassign
19 host: configManager.getConfig('crowi', 'mail:smtpHost'),
20 port: configManager.getConfig('crowi', 'mail:smtpPort'),
21 };
22
23 if (configManager.getConfig('crowi', 'mail:smtpUser') && configManager.getConfig('crowi', 'mail:smtpPassword')) {
24 option.auth = {
25 user: configManager.getConfig('crowi', 'mail:smtpUser'),
26 pass: configManager.getConfig('crowi', 'mail:smtpPassword'),
27 };
28 }
29 if (option.port === 465) {
30 option.secure = true;
31 }
32 }
33 option.tls = { rejectUnauthorized: false };
34
35 const client = nodemailer.createTransport(option);
36
37 debug('mailer set up for SMTP', client);
38 return client;
39}
16function Email( ) {
17
18 Resource.apply( this, arguments );
19 var authParams = null;
20 if (this.config.username !== '' || typeof process.env.DPD_EMAIL_USERNAME !== 'undefined') {
21 authParams = {
22 user: this.config.username || process.env.DPD_EMAIL_USERNAME,
23 pass: this.config.password || process.env.DPD_EMAIL_SMTP_PASSWORD
24 };
25 }
26
27
28 this.transport = nodemailer.createTransport(smtp({
29 host : this.config.host || process.env.DPD_EMAIL_HOST || 'localhost',
30 port : parseInt(this.config.port, 10) || process.env.DPD_EMAIL_PORT || 25,
31 secure : this.config.ssl,
32 //service: 'gmail',
33 auth : authParams
34 }))
35
36 this.transport.use('compile', htmlToText({}) );
37
38}
77sendEmail(options) {
78 let transporter = Nodemailer.createTransport({
79 service: Config.smtp.service,
80 auth: {
81 user: Config.smtp.user,
82 pass: Config.smtp.pass
83 }
84 });
85 let email = {
86 from: Config.smtp.from,
87 };
88 email = Object.assign(email, options);
89 transporter.sendMail(email, (err, info) => {
90 if (err) {
91 console.log(err);
92 } else {
93 console.log(`Message sent: ${info.response}`);
94 }
95 });
96}
7constructor(config) {
8 super(config);
9
10 this.setProvider(nodemailer.createTransport(sendmailTransport(this.get('provider'))));
11}

Related snippets