UNPKG

gmailclient

Version:

Cliente para enviar correos, incluir attachments, guardar listas de distribución

21 lines (18 loc) • 772 B
'use strict' const fs = require('fs'); const path = require('path'); const mediaTypes = require('../data/mediaTypes.json'); class Attachment { constructor(filepath) { this.filepath = filepath; this.filename = path.basename(filepath); this.extension = path.extname(filepath); this.absolutePath = path.isAbsolute(filepath) ? filepath : path.join(__dirname, filepath); this.base64Encoded = fs.readFileSync(filepath).toString('base64'); this.base64URLEncoded = this.base64Encoded.replace(/\+/g, '-').replace(/\//g, '_'); this.mediaType = mediaTypes.find(item => item.extension === this.extension).value; if (this.mediaType === undefined) throw Error("Media Type not supported"); } } module.exports = Attachment;