Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- const nodemailer = require('nodemailer');
- const fs = require('fs');
- // Generate test SMTP service account from ethereal.email
- // Only needed if you don't have a real mail account for testing
- nodemailer.createTestAccount((err, account) => {
- // create reusable transporter object using the default SMTP transport
- let transporter = nodemailer.createTransport({
- host: 'smtp.gmail.com',
- port: 587,
- // secureConnection: false,
- secure: false, // true for 465, false for other ports
- auth: {
- user: "abdulw976@gmail.com", // generated ethereal user
- pass: "abdulwahab" // generated ethereal password
- },
- tls: {
- ciphers:'SSLv3',
- rejectUnauthorized: false
- },
- });
- // setup email data with unicode symbols
- let mailOptions = {
- from: 'dfdh@globallogic.com', // sender address
- to: 'abdulwajid.nasar@globallogic.com', // list of receivers
- subject: 'Hello ✔', // Subject line
- text: 'Hello world?', // plain text body
- // html: '<b>Hello world?</b>' // html body
- html: 'Embedded image1: <img src="/home/moda/Pictures/errors.png"/>',
- attachments: [
- { // utf-8 string as an attachment
- filename: 'text1.txt',
- content: 'first text'
- },
- { // binary buffer as an attachment
- filename: 'text2.txt',
- content: new Buffer('second text','utf-8')
- },
- { // stream as an attachment
- filename: 'errors.png',
- content: fs.createReadStream('/home/moda/Pictures/errors.png')
- }]
- };
- // send mail with defined transport object
- transporter.sendMail(mailOptions, (error, info) => {
- if (error) {
- return console.log(error);
- }
- console.log('Message sent: %s', info.messageId);
- // Preview only available when sending through an Ethereal account
- console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
- // Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@blurdybloop.com>
- // Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
- });
- });
Add Comment
Please, Sign In to add comment