title: Performance while sending mail with nodemailer
body: <p>I have a performance related problem. I have a reservation system where after reservation is put into database the <code>onWrite</code> cloud function send email with <code>nodemailer</code> and deletes event so it's no longer available for other people to reserve.</p>
  
  <p>The problems:
  - I don't know how to make a callback that would confirm sending email
  - sending email and removing event takes even up to a minute which is really slow</p>
  
  <p>I don't want to show in client code how to remove events from database from obvious reasons. What are other options here? </p>
  
  <pre><code>exports.sendEmailConfirmation = functions.database.ref('/reservations/{reservation}').onWrite(event =&gt; {
  
      const moment = require('moment');
      moment.locale('pl');
  
      admin.database().ref('/users').orderByChild('place').equalTo(event.data.val().placeId).once('child_added', function(snapshot) {     
  
          // create reusable transporter object using the default SMTP transport
          const transporter = nodemailer.createTransport({
              host: '(...)',      
              port: 465,
              secure: true, // secure:true for port 465, secure:false for port 587
              auth: {
                  user: '(...)', // TODO move to config()
                  pass: '(...)' // TODO move to config()
              }
          });
  
          // setup email data with unicode symbols
          const mailOptions = {       
              from: 'whatever', // sender address - TODO make it dynamically populated
              //replyTo: 'put user's email here',
              to: snapshot.val().email,
              bcc: '(...)',
              subject: 'Nowa rezerwacja', // Subject line - TODO make it dynamically populated
              text: 'Nowa rezerwacja\n'
                  + "\nImię i nazwisko: " + event.data.val().name
                  + "\nTelefon: " + event.data.val().number
                  + "\nEmail: " + event.data.val().email
                  + "\nTermin: " + moment.utc(event.data.val().start).format("D MMMM YYYY [o godzinie] HH:mm")
                  + "\nDo: " + event.data.val().scheduleName, // plain text body
              html: 'Nowa rezerwacja&lt;br&gt;'
                  + "&lt;br&gt;Imię i nazwisko: " + event.data.val().name
                  + "&lt;br&gt;Telefon: " + event.data.val().number
                  + "&lt;br&gt;Email: " + event.data.val().email
                  + "&lt;br&gt;Termin: " + moment.utc(event.data.val().start).format("D MMMM YYYY [o godzinie] HH:mm")
                  + "&lt;br&gt;Do: " + event.data.val().scheduleName
          };
  
          // send mail with defined transport object
          transporter.sendMail(mailOptions, (error, info) =&gt; { // TODO should be returned
              if (error) {
                  return console.log(error);
              }
  
              console.log('Message %s sent: %s', info.messageId, info.response);
  
              //move it elsewhere - maybe HTTP trigger?
              admin.database().ref('events/' + event.data.val().eventKey).remove();   
  
          });
  
      });
  
  });
  </code></pre>