Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'emailjs' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
function sendEmail( to, subject, msg, cb){
var cfg = CFG.email;
var server = email.server.connect( cfg );
server.send( {
text: msg, from: cfg.from, to: to, subject: subject
}, function (err, message) {
if (err) {
// handle error
console.log('There was an error sending the email');
console.log(err);
event('error', 'sendEmail failed', err);
if(cb)cb(err);
}else {
console.log('Email sended');
console.log(message);
event('info', 'sendEmail', message);
if(cb)cb(null, message);
}
});
var email = require('emailjs');
var server = email.server.connect({
user: 'username@gmail.com',
password: 'password',
host: 'smtp.gmail.com',
ssl: true
});
// send the message and get a callback with an error or details of the message that was sent
function alertEmail(msg) {
server.send({
text: msg,
from: 'username@gmail.com',
to: 'username@gmail.com',
subject: 'Alert'
}, function (err, message) {
console.log(err || message);
});
// console.log(params)
let smtpUser = user
let smtpPassword = password
let smtpHost = host
if (params.headers.smtp_user) {
smtpUser = params.headers.smtp_user
}
if (params.headers.smtp_password) {
smtpPassword = params.headers.smtp_password
}
if (params.headers.smtp_host) {
smtpHost = params.headers.smtp_host
}
// console.log('', smtpHost, smtpPassword, smtpUser)
if (smtpHost !== '' && smtpHost !== undefined && smtpPassword !== '' && smtpPassword !== undefined && smtpHost !== '' && smtpHost !== undefined) {
let SMTPServer = email.server.connect({
user: smtpUser,
password: smtpPassword,
host: smtpHost,
ssl: false
});
return new Promise((resolve, reject) => {
SMTPServer.send({
text: data['body'],
// html: 'Nikita',
from: data['from'],
to: data['to'],
cc: data['cc'],
bcc: data['bcc'],
subject: data['subject'],
attachment:
[
console.log('sending email');
// отправка сообщения по электронной почте
var server = emailjs.server.connect({
user : 'gmail.account.name',
password : 'gmail.account.passwod',
host : 'smtp.gmail.com',
port : 587,
tls : true
});
var headers = {
text : 'You can find your split PDF at ' + url,
from : 'youremail',
to : email,
subject: 'split pdf'
};
var message = emailjs.message.create(headers);
message.attach({
data:"<p>You can find your split PDF at " + "<a href="" + url + "">" + url + "</a></p>",
alternative: true
});
server.send(message, function(err, message) {
console.log(err || message);
});
pdftk.kill();
});
pdftk.stderr.on('data', function (data) {
if (meta !== null && meta !== undefined && (typeof meta !== 'object' || Object.keys(meta).length > 0))
body += "\n\n" + util.inspect(meta, {depth: 5}); // add some pretty printing
var msgOptions = {
from: this.from,
to: this.to,
subject: this.subject({level: level, msg: msg.split('\n')[0]}),
text: body
};
//Send mail as html
if (this.html){
msgOptions.attachment = [{data: body , alternative:true}];
}
var message = email.message.create(msgOptions);
this.server.send(message, function (err) {
if (err) self.emit('error', err);
self.emit('logged');
callback(null, true);
});
};
// ---- module dependencies ---------------------
var EM = {}
module.exports = EM
// ---- module attributes -----------------------
var mailsettings = {
host : '',
user : '',
password : '',
sender : '',
ssl : true
}
EM.server = require("emailjs/email").server.connect({
host : mailsettings.host,
user : mailsettings.user,
password : mailsettings.password
//ssl : mail.ssl
})
// ---- module exports --------------------------
EM.dispatchRegistrationMail = function(account, callback) {
var text = "welcome to educatopia\n" +
"please click the link below!" +
"http://educatopia.org/verify?user=" + account._id;
EM.server.send({
from : mailsettings.sender,
to : account.email,
subject : 'educatopia registration',
charset: 'iso-2022-jp',
header: {
'message-id': '<' + (new Date()).getTime() + '.' + process.pid + '@' + NX.Os.hostname() + '>'
}
});
NX.applyIf(config, {
content: 'text/plain; charset=' + config.charset.toLowerCase()
});
var iconv = new Iconv('UTF-8', config.charset);
var buffer = iconv.convert(config.subject || '');
config.subject = buffer.toString();
var message = email.message.create(config);
// 添付ファイル処理
if(config.files) {
if(NX.isObject(config.files)) {
config.files = [config.files];
}
if(NX.isArray(config.files)) {
config.files.forEach(function(item) {
var name = item.name;
var ext = name.substr(name.indexOf('.') + 1);
if(!item.type) {
test('deliver.send()', async () => {
const deliver = email(smtpConfig);
const token = '123.123.123';
const user = { name: 'John', email: 'john@doe.com' };
const req = { hostname: 'a-domain.com', protocol: 'http' };
await deliver.send(user, token, req);
expect(emailjs.__spy.connect).toHaveBeenCalledWith({
host: 'smtp.domain.com',
password: 'secure',
port: '465',
ssl: true,
user: 'user@domain.com'
});
expect(emailjs.__spy.send.mock.calls[0][0]).toEqual({
from: 'from@domain.com',
subject: 'Token for a-domain.com!',
text:
'Hello!\nAccess your account here: http://a-domain.com/?token=123.123.123',
to: 'john@doe.com'
});
});
...smtpConfig
});
const token = '123.123.123';
const user = { name: 'John', email: 'john@doe.com' };
const req = { hostname: 'a-domain.com', protocol: 'http' };
await deliver.send(user, token, req);
expect(emailjs.__spy.connect).toHaveBeenCalledWith({
host: 'smtp.domain.com',
password: 'secure',
port: '465',
ssl: true,
user: 'user@domain.com'
});
expect(emailjs.__spy.send.mock.calls[0][0]).toEqual({
from: 'from@domain.com',
subject: 'Token for a-domain.com!',
text:
'Hello!\nAccess your account here: http://a-domain.com/?acceptToken=123.123.123',
to: 'john@doe.com'
});
expect(deliver.tokenField).toBe('acceptToken');
});
#!/usr/bin/env node
var config = require('./config.json');
var fs = require('fs');
var express = require('express');
var app = express();
var queue = require('queue-async');
var tasks = queue(1);
var spawn = require('child_process').spawn;
var email = require('emailjs/email');
var mailer = email.server.connect(config.email);
var crypto = require('crypto');
app.use(express.bodyParser({
verify: function(req,res,buffer){
if(!req.headers['x-hub-signature']){
return;
}
if(!config.secret || config.secret==""){
console.log("Recieved a X-Hub-Signature header, but cannot validate as no secret is configured");
return;
}
var hmac = crypto.createHmac('sha1', config.secret);
var recieved_sig = req.headers['x-hub-signature'].split('=')[1];
var computed_sig = hmac.update(buffer).digest('hex');