module.exports = (task, campaignInfo) => {

  // Ref https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SES.html#sendEmail-property

  const email = {
    Source: `"${campaignInfo.fromName}" <${task.email}>`, // From email
    Destination: { // To email
      ToAddresses: [`<${task.email}>`] // Set name as follows https://docs.aws.amazon.com/ses/latest/DeveloperGuide/email-format.html
    },
    Message: {
      Body: {},
      Subject: { // Subject
        Data: campaignInfo.emailSubject
      }
    }
  };

  if (campaignInfo.type === 'Plaintext') { // Send as plaintext if plaintext, else send as HTML (no other format concerns us)
    Object.assign(email.Message.Body, { Text: { Data: campaignInfo.emailBody } });
  } else {
    Object.assign(email.Message.Body, { Html: { Data: campaignInfo.emailBody } });
  }

  return email;
};

module.exports = (task, campaignInfo) => {

  // Ref https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SES.html#sendEmail-property

  const email = {
    Source: `"${campaignInfo.fromName}" <${campaignInfo.fromEmail}>`, // From email
    Destination: { // To email
      ToAddresses: [`<${task.email}>`] // Set name as follows https://docs.aws.amazon.com/ses/latest/DeveloperGuide/email-format.html
    },
    Message: {
      Body: {},
      Subject: { // Subject
        Data: campaignInfo.emailSubject
      }
    }
  };

  if (campaignInfo.type === 'Plaintext') { // Send as plaintext if plaintext, else send as HTML (no other format concerns us)
    Object.assign(email.Message.Body, { Text: { Data: campaignInfo.emailBody } });
  } else {
    Object.assign(email.Message.Body, { Html: { Data: campaignInfo.emailBody } });
  }

  return email;
};

Fix 'from' address SES verification bug
Fix 'from' address SES verification bug

The FROM address was being set to the TO address for each sent email.
This caused SES to reject the email because the sender was not verified.

So emails could only be sent to the owner of the SES account.

Emails sent to the test server were successful because there is
no source address validation.
