SendRawEmailCommand Documentation example doesn't work: Cannot read properties of undefined (reading 'byteLength')

0

Hi, I am trying to run the following code from the documentation but I am getting the error "Cannot read properties of undefined (reading 'byteLength')".

I tried base64 encoding the entire Data String but it still returns the same error.

// The following example sends an email with an attachment: const input = { "Destinations": [], "FromArn": "", "RawMessage": { "Data": "From: sender@example.com\nTo: recipient@example.com\nSubject: Test email (contains an attachment)\nMIME-Version: 1.0\nContent-type: Multipart/Mixed; boundary="NextPart"\n\n--NextPart\nContent-Type: text/plain\n\nThis is the message body.\n\n--NextPart\nContent-Type: text/plain;\nContent-Disposition: attachment; filename="attachment.txt"\n\nThis is the text in the attachment.\n\n--NextPart--" }, "ReturnPathArn": "", "Source": "", "SourceArn": "" }; const command = new SendRawEmailCommand(input); const response = await client.send(command); /* response == { "MessageId": "EXAMPLEf3f73d99b-c63fb06f-d263-41f8-a0fb-d0dc67d56c07-000000" } */ // example id: sendrawemail-1469118548649

https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/ses/command/SendRawEmailCommand/

Full Error:

ypeError: Cannot read properties of undefined (reading 'byteLength') at fromArrayBuffer (/var/runtime/node_modules/@aws-sdk/node_modules/@smithy/util-buffer-from/dist-cjs/index.js:6:60) at Object.toBase64 [as base64Encoder] (/var/runtime/node_modules/@aws-sdk/node_modules/@smithy/util-base64/dist-cjs/toBase64.js:5:68) at se_RawMessage (/var/runtime/node_modules/@aws-sdk/client-ses/dist-cjs/protocols/Aws_query.js:4267:35) at se_SendRawEmailRequest (/var/runtime/node_modules/@aws-sdk/client-ses/dist-cjs/protocols/Aws_query.js:4661:31) at se_SendRawEmailCommand (/var/runtime/node_modules/@aws-sdk/client-ses/dist-cjs/protocols/Aws_query.js:546:12) at serialize (/var/runtime/node_modules/@aws-sdk/client-ses/dist-cjs/commands/SendRawEmailCommand.js:45:55) at /var/runtime/node_modules/@aws-sdk/node_modules/@smithy/middleware-serde/dist-cjs/serializerMiddleware.js:12:27 at /var/runtime/node_modules/@aws-sdk/node_modules/@smithy/middleware-endpoint/dist-cjs/endpointMiddleware.js:32:16 at async /opt/nodejs/node_modules/@serverless/sdk/index.js:4420:36 at async /opt/nodejs/node_modules/@serverless/sdk/index.js:4418:41

Leon
已提問 8 個月前檢視次數 191 次
1 個回答
0

he error you are encountering seems to be related to how the SDK is handling the input data for the SendRawEmailCommand. The error message indicates that it's trying to read the byteLength property of something that is undefined, which suggests that the input data is not being processed correctly.

To troubleshoot and resolve this issue, here are a few steps you can take:

  • Check Input Data: Ensure that the input object passed to the SendRawEmailCommand constructor is correctly formatted according to the documentation. Double-check the structure of the input.RawMessage.Data property, making sure it contains the raw email message data as a string.
  • Verify MIME Format: The raw email message data should follow the MIME format, with appropriate headers and boundaries for multipart messages. Make sure the content is properly formatted according to MIME standards.
  • Base64 Encoding: If your email message contains binary data or non-ASCII characters, make sure that the Data property of the RawMessage object is base64-encoded. However, ensure that you're encoding the entire raw message data, not just a portion of it.
  • Check AWS SDK Version: Ensure that you're using the latest version of the AWS SDK for JavaScript. It's possible that there might be a bug or compatibility issue with the specific version you're using.
  • Debugging: Add logging statements to your code to inspect the input object and its properties before passing it to the SendRawEmailCommand. This can help you identify any discrepancies or unexpected values.
profile picture
專家
已回答 7 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南