forwardemail / email-templates

Create, preview (browser/iOS Simulator), and send custom email templates for Node.js. Made for @forwardemail, @ladjs, @cabinjs, @spamscanner, and @breejs.
https://forwardemail.net/docs/send-emails-with-node-js-javascript
MIT License
3.67k stars 337 forks source link

Documentation/Example request on how to use custom-fonts-in-emails #362

Closed katp4 closed 5 years ago

katp4 commented 5 years ago

Hello,

I'm trying to add custom fonts to my emails. I've included the .otf files in my directory, i've installed custom-fonts-in-emails but the only thing mentioned in the documentation is to add it to my config.locals which is very vague.

Could you be able to add more documentation or at least an example on how to do that?

Thanks

harveyconnor commented 5 years ago

You can use custom fonts in your css.

includes/style.css

@font-face {
  font-family: 'Roboto';
  src: url('../../../assets/fonts/Roboto.otf') format('opentype')
}

body {
  font-family: 'Roboto', Arial, Helvetica, sans-serif;
}

And in your html file html.pug

head
  style
    include includes/style.css
niftylettuce commented 5 years ago

@katp4 here you go:

App example:

const path = require('path');
const customFonts = require('custom-fonts-in-emails');
const Email = require('email-templates');

(async () => {
  try {
    const header = await customFonts.png2x({
      text: 'Make something people want',
      fontNameOrPath: 'GoudyBookletter1911',
      fontColor: 'white',
      backgroundColor: '#ff6600',
      fontSize: 40
    });

    const email = new Email();

    await email.send({
      template: 'some-template',
      message: {
        to: 'elon@spacex.com'
      },
      locals: {
        name: 'Elon',
        header
      }
    });
  } catch (err) {
    throw err;
  }
))();

Template some-template.pug:

!= header
p Welcome to Mars, the red planet.

Ref: https://github.com/ladjs/custom-fonts-in-emails

katp4 commented 4 years ago

a bit late but thanks guys!