Socket
Book a DemoInstallSign in
Socket

@essential-projects/email

Package Overview
Dependencies
Maintainers
4
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@essential-projects/email

Service to send mails

latest
npmnpm
Version
3.0.0
Version published
Weekly downloads
3
Maintainers
4
Weekly downloads
 
Created
Source

Email module

Configuration

  • Create the Files config/ENVIRONMENT/email/email_service.json and config/ENVIRONMENT/email/email_repository.json in your project
  • Set the content of these config-files to {}

Setup

  • In your http-extension-module in your application run npm install @5minds/email --save
  • In your http-extensions ioc_module.js
  • Require the module with const email = require('@5minds/email/ioc_module');
  • Register the module at the IoC-Container with: email.registerInContainer(container);

Usage

  • Let the IoC-Container inject the EmailService into the services that need to send emailService

Methods

  • sendSMTPMail(smtpSetup, mail)
  • sendSMTPMails(smtpSetup, mails)
  • sendSendgridMail(sendgridAPIKay, mail)
  • sendSendgridMails(sendgridAPIKay, mails)

Parameter-descriptions:

smtpSetup

{ 
  host: 'smtp.gmail.com', 
  port: 465, 
  username: 'heiko.mathes@5minds.de', 
  password: '*******************', 
}

SendgridAPIKey

'*******************'

mail

text, html and template are all optional, but at least one of them has to exist

{
  senderName: 'Heiko Mathes',
  senderAddress: 'heiko.mathes@gmail.com', 
  to: ['heiko.mathes@gmail.com'], 
  subject: 'testMail',
  text: 'PlainText',
  html: '<b>styledtext</b>'
  template: template-object
  attachments: attachments-object
}, 

template-object

the template-object can have one ot the following forms

{ 
  path: '/path/to/a/handlebars/file.hbs', 
  data: { 
    testText: 'HAI!',
  }
}

or

{ 
  source: '<html><body>testText: <b>{{testText}}</b></body></html>', 
  data: { 
    testText: 'HAI!',
  }
}

or

{ 
  handlebarsTemplate: a_compiled_handlebars_template_object, 
  data: { 
    testText: 'HAI!',
  }
}

attachments-object

See Nodemailer - Using attachments

Example

this.emailService.sendSMTPMail({ 
  host: 'smtp.gmail.com', 
  port: 465, 
  username: 'heiko.mathes@5minds.de', 
  password: '************************', 
}, { 
  senderName: 'Heiko Mathes', 
  to: ['heiko.mathes@gmail.com'], 
  subject: 'testMail', 
  template: { 
    path: './testTemplate.hbs', 
    data: { 
      testText: 'HAI!', 
    }, 
  }, 
}); 

Config

Service-Config

{
}

Repository-Config

{
  "overwriteReceiver": "some@mail.address", // optional, overwrites the direct receiver of all mails
  "smtp": { // optional, default smtp-settings
    "host": "smtp.gmail.com",
    "port": 465,
    "username": "heiko.mathes@5minds.de",
    "password": "*******************"
  },
  "sendgrid": { // optional, default sendgrid-settings
    "APIKey": "*******************"
  }
}

Keywords

email

FAQs

Package last updated on 19 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts