AWS ses api with X-SES-CONFIGURATION-SET header + email queue failing

Your software
My Mautic version is: 4.4.4 (this doesn’t seem to matter as i tried 4.4.5 and 4.4.9)
My PHP version is: php 8.0.29
My Database type and version is: percona version 8.0.31-23 (via docker image )

Your problem
My problem is: When I have the following configuration:

  • AWS SES API
  • X-SES-CONFIGURATION-SET headers set
  • Email Sending = Queue

Certain types of emails (password reset, email directly to a contact) don’t seem to be sending out. However planned segment emails seem to be going through and sending.

These errors are showing in the log:

root@a58e9648afdc:/var/www/html# tail -f var/logs/mautic_prod-2023-08-08.php
[2023-08-08 20:05:27] mautic.ERROR: SES API Error: Start of structure or map found where not expected
[2023-08-08 20:07:42] mautic.ERROR: SES API Error: Start of structure or map found where not expected

My impression is that the payload being sent to the ses api is “not correct” when serializing / deserializing the mailer message to / from the email queue. For instance, I added a logger statement into app/bundles/EmailBundle/Swiftmailer/Transport/AmazonAPITransport.php in the getAmazonMessage(\Swift_Mime_SimpleMessage $message) function.

            $headers            = $message->getHeaders();
            $this->logger->error("X-SES:");
            $this->logger->error(print_r($headers->get('X-SES-CONFIGURATION-SET'), true));
            if ($headers->has('X-SES-CONFIGURATION-SET')) {
	         $this->logger->error("HAS X-SES");
                 $sesArray['ConfigurationSetName'] = $headers->get('X-SES-CONFIGURATION-SET');
            }

and go back something like the following in the logs:

[2023-08-01 20:07:02] mautic.ERROR: Array (     [FromEmailAddress] => "XXXXXXXXXXXXX     [Destination] => Array         (             [ToAddresses] => Array                 (                     [0] => xxxx.xxxxxx@xxxx.com
         )          )      [ReplyToAddresses] => Array         (             [0] => xxxx@xxxx.com         )      [ConfigurationSetName] => Swift_Mime_Headers_UnstructuredHeader Object         (             [value:Swift_Mime_Headers_UnstructuredHeader:private] => xxx-
ses             [name:Swift_Mime_Headers_AbstractHeader:private] => X-SES-CONFIGURATION-SET             [encoder:Swift_Mime_Headers_AbstractHeader:private] => Swift_Mime_HeaderEncoder_QpHeaderEncoder Object                 (                     [charStream:protected
] => Swift_CharacterStream_NgCharacterStream Object                         (                             [charReader:Swift_CharacterStream_NgCharacterStream:private] =>                              [charReaderFactory:Swift_CharacterStream_NgCharacterStream:private]
 => Swift_CharacterReaderFactory_SimpleCharacterReaderFactory Object                                 (                                 )                              [charset:Swift_CharacterStream_NgCharacterStream:private] => utf-8                             [data
s:Swift_CharacterStream_NgCharacterStream:private] =>                              [datasSize:Swift_CharacterStream_NgCharacterStream:private] => 0                             [map:Swift_CharacterStream_NgCharacterStream:private] =>                              [map
Type:Swift_CharacterStream_NgCharacterStream:private] => 0                             [charCount:Swift_CharacterStream_NgCharacterStream:private] => 0                             [currentPos:Swift_CharacterStream_NgCharacterStream:private] => 0
    )                      [filter:protected] =>                      [safeMap:protected] => Array                         (                             [97] => a                             [98] => b                             [99] => c
 [100] => d                             [101] => e                             [102] => f                             [103] => g                             [104] => h                             [105] => i                             [106] => j
        [107] => k                             [108] => l                             [109] => m                             [110] => n                             [111] => o                             [112] => p                             [113] => q
               [114] => r                             [115] => s                             [116] => t                             [117] => u                             [118] => v                             [119] => w                             [120] => x
                      [121] => y                             [122] => z                             [65] => A                             [66] => B                             [67] => C                             [68] => D                             [69] => E
                        [70] => F                             [71] => G                             [72] => H                             [73] => I                             [74] => J                             [75] => K                             [76] => L
                        [77] => M                             [78] => N                             [79] => O                             [80] => P                             [81] => Q                             [82] => R                             [83] => S
                        [84] => T                             [85] => U                             [86] => V                             [87] => W                             [88] => X                             [89] => Y                             [90] => Z
                        [48] => 0                             [49] => 1                             [50] => 2                             [51] => 3                             [52] => 4                             [53] => 5                             [54] => 6
                        [55] => 7                             [56] => 8                             [57] => 9                             [32] =>                               [33] => !                             [42] => *                             [43] => +
                        [45] => -                             [47] => /                         )                  )              [lineLength:Swift_Mime_Headers_AbstractHeader:private] => 78             [lang:Swift_Mime_Headers_AbstractHeader:private] =>
  [charset:Swift_Mime_Headers_AbstractHeader:private] => utf-8             [cachedValue:Swift_Mime_Headers_AbstractHeader:private] => xxx-ses         )      [Content] => Array         (             [Raw] => Array                 (                     [Data] => Messa
ge-ID: <bacxxxxxxxxx@xxxxxx.com> Date: Tue, 01 Aug 2023 20:06:23 +0000 Subject: Mautic password reset From: XXXXXX <xxxx@xxxx.com> Reply-To: xxx@xxx.com To: the test <xxx.xxxxxxx@xxxx.com> MIME-Version
: 1.0 Content-Type: multipart/alternative;  boundary="_=_swift_1690920383_ec92b0ffd7202dcdb3043278bcdfad41_=_" X-SES-CONFIGURATION-SET: epl-ses List-Unsubscribe: <{unsubscribe_url}>   --_=_swift_1690920383_ec92b0ffd7202dcdb3043278bcdfad41_=_ Content-Type: text/plain
; charset=utf-8 Content-Transfer-Encoding: quoted-printable  Hi xxx,  You requested a password reset. Click the link below to reset=  your password.  https://xxxx.com/passwordresetconfi= rm?token=3D65n8vtmjpycx6t7ln47f6imvdui1v4y8783zlg5r8fp1urc7
rvoxxx5ijw3qzesqoxx  --_=_swift_1690920383_ec92b0ffd7202dcdb3043278bcdfad41_=_ Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable  Hi xxx,<br /><br /> <br /><br /> You requested a password reset. Click=  the link below to reset your pas
sword.<br /><br /> <br /><br /> <a hre= f=3D"https://xxxxx.com/passwordresetconfirm?token=3D65n8v= tmjpycx6t7ln47f6imvdui1v4y8783zlg5r8fp1urc7rvo5ijw3qzesqoxxx">https://xxxx.com/passwordresetconfirm?token=3D65n8vtmjpycx6t7ln47f6
imv= dui1v4y8783zlg5r8fp1urc7rvo5ijw3qzesqoxxx</a><img height=3D"1" width=3D"1" s= rc=3D"data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=3D" alt=3D"= " />  --_=_swift_1690920383_ec92b0ffd7202dcdb3043278bcdfad41_=_--                  )          )  )  [] {"ho
stname":"2952a7718101","pid":3858789}

Steps I have tried to fix the problem:

  1. tried different version of mautic 4.4.4 and 4.4.9 (still the same error)
  2. Tried removing X-SES-CONFIGURATION-SET (and it works) but i need this header set for tracking and other stuff.
  3. Tried looking for similar issues (like this or this but they don’t apply exactly (the last topic might but there isn’t much info or movement).
  4. Check to see if the vendor → aws sdk changed but they all seem to be on ‘3.222.1’

I’m out of ideas and hoping someone ran into the same issue and could help.

You can probably reproduce this by using the following docker-compose.yml

version: '3.4'

services:

  mauticdb:
    image: percona/percona-server:latest
    container_name: mauticdb
    ports:
      - "3306:3306"
    volumes:
      - mysql_data:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=mysecret
    # command:
    #   --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci
    networks:
      - mautic-net

  mautic:
    image: mautic/mautic:v4
    container_name: mautic2
    # build:
    #   context: .
    #   dockerfile: ./Dockerfile
    links:
      - mauticdb:mysql
    depends_on:
      - mauticdb
    ports:
      - 8080:80
    # volumes:
      # -  ./local.php:/var/www/html/app/config/local.php:rw
      # - ./mautic_source/app:/var/www/html/app
      # - ./xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
      # - ./error_reporting.ini:/usr/local/etc/php/conf.d/error_reporting.ini
    environment:
      # - mautic_data/:var/www/html
      - MAUTIC_DB_HOST=mauticdb
      - MYSQL_PORT_3306_TCP=3306
      - MAUTIC_DB_USER=root
      - MAUTIC_DB_PASSWORD=mysecret
      - MAUTIC_DB_NAME=mautic
      - MAUTIC_RUN_CRON_JOBS=true
    extra_hosts:
      - host.docker.internal:host-gateway
    networks:
      - mautic-net

volumes:
  mysql_data:
    driver: local
  mautic_data:
    driver: local
networks:
  mautic-net:
    driver: bridge

Then do the following:

  • docker-compose up
  • go through installation
  • for email settings
    • ses api
    • add credentials
    • add header X-SES-CONFIGURATION-SET → something
    • change from “process immediately” to “queue”
    • quickly add a user
    • either do a) logout and password reset or b) go to contact and click “send email” (fill in and send)
    • run the php /var/www/html/bin/console mautic:emails:send command (to process queue)
    • view logs and you should see mautic.ERROR: SES API Error: Start of structure or map found where not expected
    • if you remove the X-SES-CONFIGURATION-SET header and redo the password reset step