title: Node.js sending an email with image attachment using nodemailer
body: <p>I'm trying to send an email from a post request. I'm using Express and nodemailer. I'm confused by 'fs' My email is getting sent but the image is not included as an attachment. I checked the docs but they all seem to send up static files not files being streamed in from a form request.</p>
  
  <pre><code>var smtpTransport = nodemailer.createTransport("SMTP",{
    service: "Gmail",
    auth: {
      user: "gmail_address@gmail.com",
      pass: "password_for_gmail_address"
    }
  });
  
  app.get('/', function(req, res){
      res.send('&lt;form method="post" enctype="multipart/form-data"&gt;'
        + '&lt;p&gt;Post Title: &lt;input type="text" name="title"/&gt;&lt;/p&gt;'
        + '&lt;p&gt;Post Content: &lt;input type="text" name="content"/&gt;&lt;/p&gt;'
        + '&lt;p&gt;Image: &lt;input type="file" name="image"/&gt;&lt;/p&gt;'
        + '&lt;p&gt;&lt;input type="submit" value="Upload"/&gt;&lt;/p&gt;'
        + '&lt;/form&gt;');
    })
  
  app.post('/', function(req, res, next){
    var mailOptions = {
      from: "gmail_address@gmail.com", // sender address
      to: "somebodyelse@example.com", // list of receivers
      subject: req.body.title, // Subject line
      text: req.body.content, // plaintext body
      attachments:[
        {
          fileName: req.body.title,
          streamSource: req.files.image
        }
      ]
    }
  
    smtpTransport.sendMail(mailOptions, function(error, response){
      if(error){
        console.log(error);
        res.send('Failed');
      }else{
        console.log("Message sent: " + response.message);
        res.send('Worked');
      }
    });   
  });
  </code></pre>