arithmetric / aws-lambda-ses-forwarder

Serverless email forwarding using AWS Lambda and SES
MIT License
1.7k stars 450 forks source link

Retain Original 'From'-Email-Address #134

Open hacnet opened 2 years ago

hacnet commented 2 years ago

Hi, fromText details are often insufficient, so I brought back the original From-Email-Address, while replacing the @ sign so that it doesn't interfere with the verified sender:

  // SES does not allow sending messages from an unverified address,
  // so replace the message's "From:" header with the original
  // recipient (which is a verified domain)
  header = header.replace(
    /^from:[\t ]?(.*(?:\r?\n\s+.*)*)/mgi,
    function(match, from) {
      var fromText;
      if (data.config.fromEmail) {
//    fromText = 'From: ' + from.replace(/<(.*)>/, '').trim() +
//    fromText = 'From: ' + from.replace(/<|>|/g, '').replace('@', '.').trim() +
      fromText = 'From: ' + from.replace(/<|>|/g, '').replace(/@/g, '.').trim() +
        ' <' + data.config.fromEmail + '>';
      } else {
        fromText = 'From: ' + from.replace('<', 'at ').replace('>', '') +
        ' <' + data.originalRecipient + '>';
      }
      return fromText;
    });