const {createTransport} = require('nodemailer');
const defaults = require('lodash/defaults');
const {renderFile} = require('ejs');

const transporter = createTransport(process.env.MAIL_URL);
const defaultMailOptions = {
  from: `"Let's run" <foo@blurdybloop.com>`
};

const EMAIL = {
    *sendRemoveConfirmation({ name, email, id }) {
        const mailOptions = defaults({
            to: email,
            subject: 'Potwierdź rezygnację z uczestnictwa'
        }, defaultMailOptions);
        
        const firstName = name.split(/\s/)[0];
        const confirmationUrl = 'http://generallyfake';

        mailOptions.html = yield new Promise((resolve) => {
            renderFile('private/remove_confirmation.ejs', { firstName, confirmationUrl }, (err, html) => {
                if (err) {
                    throw new Error(err);
                }

                resolve(html);
            });
        });

        return new Promise((resolve) => {
            transporter.sendMail(mailOptions, (err, info) => {
                if (err) {
                    throw new Error(err);
                }
                resolve(info);
            });
        });
    }
};

module.export = EMAIL;
@@ -326,14 +326,21 @@
 , id
+, token
  %7D) %7B%0A
-
     
@@ -454,16 +454,24 @@
 stnictwa
+ w biegu
 '%0A      
@@ -588,31 +588,58 @@
 l = 
-'http://generallyfake';
+%60$%7Bprocess.env.ROOT_URL%7D/confirm/$%7Bid%7D/$%7Btoken%7D%60;%0A
 %0A%0A  

correct confirmation link