Techioz Blog

Aws::SES::Errors::InvalidParameterValue: 添付ファイル付きのネストされたグループ Ruby send_raw_email

概要

Ruby の aws ses のドキュメントを使用したとき、次のように言います。 https://translate.google.com/translate?hl=ja&sl=en&tl=ja&u=https://www.rubydoc.info/gems/aws-sdk-ses/1.14.0/Aws%2FSES%2FClient:send_raw_email

そのコードを試してみると、次のようなエラーが発生します。 Aws::SES::Errors::InvalidParameterValue: ネストされたグループ

send_raw_email を使用して電子メールを送信しようとしましたが、Ruby 用の AWS SES のドキュメントを使用してドキュメント内のコードをテストすると、プログラムが次のメッセージを返します: Aws::SES::Errors::InvalidParameterValue: Nested group and not send email

解決策

これは補間に関する問題です。これを使用して解決します。

# open and read archive to send in attachment
file = File.open(path_from_csv_created).read

resp = ses_client.send_raw_email(
      source: 'email_send',
      destinations: ['email_to_receive'],
      raw_message: {
        data: <<~MESSAGE
          From: email_send
          To: email_to_receive
          Subject: Test email (contains an attachment)
          MIME-Version: 1.0
          Content-type: Multipart/Mixed; boundary="NextPart"

          --NextPart
          Content-Type: text/plain

          bodyyyy

          --NextPart
          Content-Type: application/csv;
          Content-Disposition: attachment; filename="#{file_csv_name}"

          #{file}
        MESSAGE
      }
    )