New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@nodefony/mail-bundle

Package Overview
Dependencies
Maintainers
0
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nodefony/mail-bundle

Nodefony Framework Bundle mail

  • 7.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
16
decreased by-78.08%
Maintainers
0
Weekly downloads
 
Created
Source

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: "user@gmail.com",
           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("admin@nodefony.com", "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}" <admin@nodefony.net>`,
    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 = 'admin@nodefony.net';
  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

Keywords

FAQs

Package last updated on 03 Jan 2025

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc