npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@nodefony/mail-bundle

v7.0.0-beta.22

Published

Nodefony Framework Bundle mail

Downloads

163

Readme

Welcome to mail-bundle

Register and Configure mail Bundle (Core Bundle)

For a Register mail-bundle add mail: true in config framework

./config/config.js

module.exports = {
  system: {
    /**
    * BUNDLES CORE
    */
    mail: true
  }
}

Override mail-bundle configuration your bundle

./app/config/config.js

/**
 *  OVERRIDE MAIL Bundle
 *
 *   @see FRAMEWORK MAIL config for more options
 *     https://nodemailer.com
 *
 *
 */
 "mail-bundle": {
   nodemailer: {
     default: "free",
     transporters: {
       free: {
         host: "smtp.free.fr",
         port: 465,
         secure: true, // true for 465, false for other ports
         auth: {
           user: "username", // generated  user
           pass: "passwd" // generated  password
         }
       },
       gmail : {
         host: "smtp.gmail.com",
         port: 465,
         secure: true, // true for 465, false for other ports
         auth: {
           user: "[email protected]",
           pass: "xxxxxxxxx"
         },
         tls: {
           // do not fail on invalid certs
           rejectUnauthorized: false
         }
       }
     }
   }
 }

Example to use :

Check transporters with sendTestMail

./controller/defaultController.js

mailAction() {
  return this.mailer.sendTestMail("[email protected]", "gmail", this.context)
    .catch((e) => {
      throw e;
    });
}

Complete example


const vCardsJS = require('vcards-js');
const puppeteer = require('puppeteer');
...


async indexAction() {
  switch(this.method){
    case "POST":
      if (this.query.mail){
        return this.sendEmail(this.query.mail)
        .then((info) =>{
          this.logger(info, "INFO", "EMAIL");
          return this.redirectToRoute("route-after-sended");
        });
      }else{
        return this.redirectToRoute("myroute");
      }
      break;
  }
}

async sendEmail(to) {
  let res = await this.twigToHtml();
  const message = {
    to: to,
    from: `"${this.mailer.authorName}" <[email protected]>`,
    subject: `${this.kernel.projectName} ✔`, // Subject line
    html: res, // html body
    attachments: [{
      // binary buffer as an attachment
        filename: 'nodefony.pdf',
        content: await this.renderPdf({}, {
          queryString: {
            mail: true
          }
        })
      }, {
      // define custom content type for the attachment
        filename: 'nodefony.vcf',
        content: this.renderVcard(),
        contentType: 'text/vcard'
    }]
  };
  // sendMail(message, transporterName, context)
  // sendMail(message,"gmail", this.context);
  return await this.sendMail(message);
}

async twigToHtml() {
  let file = path.resolve(this.bundle.viewsPath, "index.html.twig");
  let res = await this.renderTwigFile(file)
    .catch((e) => {
      throw e;
    });
  return this.mailer.juiceResources(res, null, this.context);
}

// vcard example
renderVcard() {
  let vCard = vCardsJS();
  //set properties
  vCard.firstName = 'admin';
  vCard.lastName = 'admin';
  vCard.organization = 'Nodefony';
  vCard.photo.attachFromUrl('https://cdn.nodefony.com/app/images/app-logo.png', 'JPEG');
  vCard.logo.attachFromUrl('https://cdn.nodefony.com/app/images/app-logo.png', "PNG");
  vCard.workPhone = '+033xxxxxxxxxx';
  vCard.birthday = new Date(xxxx, xx, xx);
  vCard.title = 'Software Developer ';
  vCard.url = this.generateAbsoluteUrl("myurl", true);
  vCard.gender = 'M';
  vCard.email = '[email protected]';
  vCard.source = this.generateAbsoluteUrl("render-vcard", true);
  vCard.homeAddress.label = 'Home Address';
  vCard.homeAddress.street = '';
  vCard.homeAddress.city = '';
  vCard.homeAddress.stateProvince = '';
  vCard.homeAddress.postalCode = '';
  vCard.homeAddress.countryRegion = '';
  vCard.socialUrls.github = 'https://github.com/nodefony';
  //vCard.note = '';
  return vCard.getFormattedString();
}

// RENDER PDF ON attachement with puppeteer
async renderPdf(options, query = {}) {
  const browser = await puppeteer.launch({
    headless: true,
    ignoreHTTPSErrors:true,
    defaultViewport:null
  });
  options = nodefony.extend({
    //format: 'A6',
    scale: 0.8,
    printBackground: true,
    //width: '1300px',
    preferCSSPageSize: false,
    displayHeaderFooter: false,
    //headerTemplate: ,
    landscape: false,
    margin: {
      top: "30px",
      bottom:"30px",
      right:"0px",
      left:"0px"
    }
  }, options);
  const page = await browser.newPage();
  await page.goto(this.generateAbsoluteUrl("route_page_to_transform", query));
  await page.emulateMedia("print");
  let buffer = await page.pdf(options);
  await browser.close();
  return buffer;
}

Authors

License