Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var nodemailer = require("nodemailer");
- var smtpTransport = nodemailer.createTransport("SMTP",{
- service: "Gmail",
- auth: {
- user: "gmail.user@gmail.com",
- pass: "gmailpass"
- }
- });
- smtpTransport.sendMail({
- from: "My Name <me@example.com>", // sender address
- to: "Your Name <you@example.com>", // comma separated list of receivers
- subject: "Hello ✔", // Subject line
- text: "Hello world ✔" // plaintext body
- }, function(error, response){
- if(error){
- console.log(error);
- }else{
- console.log("Message sent: " + response.message);
- }
- });
- <form id="mainForm">
- <input type="file" id="fileUpload">
- <input type="submit" id="submit" name="submit">
- </form>
- var app = express();
- var Busboy = require('busboy');
- var nodemailer = require("nodemailer");
- var smtpTransport = nodemailer.createTransport("SMTP",{
- service: "Gmail",
- auth: {
- user: "gmail.user@gmail.com",
- pass: "gmailpass"
- }
- });
- app.post('/email', function(req, res){
- var busboy = new Busboy({ headers: req.headers });
- var attachments = [];
- var mailOptions = {
- from: "My Name <me@example.com>", // sender address
- to: "Your Name <you@example.com>", // comma separated list of receivers
- subject: "Hello ✔", // Subject line
- text: "Hello world ✔" // plaintext body
- };
- busboy
- .on('file', function(fieldname, file, filename, encoding, mimetype){
- attachments.push({
- filename: filename,
- content: file.toString('base64'),
- encoding: 'base64'
- });
- })
- .on('finish', function() {
- mailOptions.attachments = attachments;
- smtpTransport.sendMail(mailOptions, function (err, info) {
- if (err) {
- //handle error
- }
- // email sent
- });
- });
- });
Add Comment
Please, Sign In to add comment