Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

10MB+ Attachments Silently Fail #124

Open
adrianmace opened this issue Aug 16, 2020 · 1 comment
Open

10MB+ Attachments Silently Fail #124

adrianmace opened this issue Aug 16, 2020 · 1 comment

Comments

@adrianmace
Copy link

It would be excellent to have this function call sendMessage() again, but this time email the intended recipient address with a simple, "I couldn't process this message. The file in S3 is {FILENAME}."

@adrianmace
Copy link
Author

Here's a crappy workaround I wrote super quickly just so that I ensured I was not missing emails.

/**
 * Send email using the SES sendRawEmail command.
 *
 * @param {object} data - Data bundle with context, email, etc.
 *
 * @return {object} - Promise resolved with data.
 */
exports.sendMessage = function(data) {
  var params = {
    Destinations: data.recipients,
    Source: data.originalRecipient,
    RawMessage: {
      Data: data.emailData
    }
  };
  data.log({
    level: "info",
    message: "sendMessage: Sending email via SES. Original recipients: " +
      data.originalRecipients.join(", ") + ". Transformed recipients: " +
      data.recipients.join(", ") + "."
  });
  return new Promise(function(resolve, reject) {
    data.ses.sendRawEmail(params, function(err, result) {
      if (err) {
        // If we encounter an error, we should let the recipient know at least so they can go and get the message from S3.
        params = {
          Destination: {
            ToAddresses: data.recipients
          },
          Source: data.originalRecipient,
          Message: {
            Subject: {
              Data: "Lambda: Email received but could not be forwarded!"
            },
            Body: {
              Text: {
                Data: "Hello from Lambda. I failed to forward something to you. The email ID is: " + data.email.messageId
              }
            }
          }
        };
        data.ses.sendEmail(params, function(err, result) {
          if (err) {
            data.log({
              level: "error",
              message: "sendEmail() failed to send a failure notification.",
              error: err,
              stack: err.stack
            });
            return reject(new Error('Error: Sending of failure notification failed.'));
          }
          data.log({
            level: "info",
            message: "Original failed, but sendEmail() of failure was successful.",
            result: result
          });
          resolve(data);
        });
      };
      data.log({
        level: "info",
        message: "sendRawEmail() successful.",
        result: result
      });
      resolve(data);
    });
  });
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant