Module - Mail
To it’s core, firstly
provides you the ability to send emails. For this, we didn’t reinvent the
wheel and use the great nodemailer package.
Once you have it setup, assign you the role Mail.Admin
(You can get it via
Roles_Mail.Mail_Admin
), and in Admin UI, you will be able to see all mails in the entity named
FF Mails
.
Installation
Section titled “Installation”npm add firstly@latest -D
import { mail } from 'firstly/mail/server'
export const api = remultApi({ modules: [mail()],})
Anywhere in your code you can then:
import { remult } from 'remult'
await remult.context.sendMail('my_first_mail', { to: 'hello@example.com', subject: 'Hello from firstly', sections: [ { html: 'hello <b>world</b> 👋' }, { html: 'Did you star remult repo ?', cta: { html: 'Star it', link: 'https://github.com/remult/remult' }, }, ],})
The result will be something like this:
You can see the structure of the mail in the following image:
Manually configure your service
Section titled “Manually configure your service”Configure the transport
of your email service.
export const api = remultApi({ modules: [ mail({ nodemailer: { transport: { host: '...', port: 587, secure: false, // Use `true` for port 465, `false` for all other ports auth: { user: '...', pass: '...', }, }, }, }), ],})
Global params
Section titled “Global params”Global params are applied to all mails by default and can be overridden for each mail.
export const api = remultApi({ modules: [ mail({ service: 'Cool App', footer: `Thank you for using Cool App`, // primaryColor: '#000000', // secondaryColor: '#000000', // toHtml(mailInfo) => `` // You can override the html of the mail from: { name: 'My Cool App', address: 'noreply@coolApp.com', }, }), ],})