Fix addresses convert function - compatibility with comma-separated emails

Created on 5 November 2023, 8 months ago
Updated 8 November 2023, 8 months ago

Problem/Motivation

At the moment Address:convert() cunstion allows to prepare the Address object from string or array.
Sometimes AddressTo (SymfonyMailerAdjuster::setAddressTo) can contain several addresses separated by a comma, e.g. example1@mail.com,example2@mail.com, which is allowed by RFC.
But unfortunatelly the convert() function creates only one address object for such case, which is wrong.
For some services it could be a critical point, e.g. SMTP mailgun.

Steps to reproduce

1. Configure SMTP transport plugin for mailgun
2. Try to send test mail to 2 or more recipients
3. Actual: we receive an error Expected response code "250/251/252" but got code "501", with message "501 Invalid command or cannot parse to address".
4. Expected: test mail must be sent without errors.

Proposed resolution

Explode $addresses variable

πŸ› Bug report
Status

Closed: works as designed

Version

1.4

Component

Code

Created by

πŸ‡ΊπŸ‡¦Ukraine HitchShock Ukraine

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @HitchShock
  • @hitchshock opened merge request.
  • πŸ‡ΊπŸ‡¦Ukraine HitchShock Ukraine
  • Status changed to Needs review 8 months ago
  • πŸ‡ΊπŸ‡¦Ukraine HitchShock Ukraine
  • Status changed to Closed: duplicate 8 months ago
  • πŸ‡¬πŸ‡§United Kingdom AdamPS

    Thanks for the patch, however it's more complex than that. There can be a comma inside a display name.

    Please see ✨ Add support for complex address strings in back-compatibility mode Active which this is a duplicate of.

  • Status changed to Needs review 8 months ago
  • πŸ‡ΊπŸ‡¦Ukraine HitchShock Ukraine

    @adamps
    Nope, this is not the same one.
    In #3350992 you are trying to fix the behavior for complex address strings there, but in general, the function MailerHelper::parseAddress() works already with comma-separated addresses, whereas the BaseEmailTrait::setAddress() function definitely does NOT, but should!

    That issue can take a long time to resolve, whereas this fix is simple and necessary and can be applied more quickly.
    It's just that when discussing that issue, you need to be aware that there may be more than one place with such a problem.

  • Status changed to Closed: works as designed 8 months ago
  • πŸ‡¬πŸ‡§United Kingdom AdamPS

    Ah thanks for explaining I understand now.

    If you are using BaseEmailInterface::setAddress() then you should put each address in a separate array element. The function comment points to Address::convert() which says "Can be a single element or an array". It then refers on to Address:create() which says "string containing a single email address without display name".

    So this is working as designed. You can put the explode into your calling code, or even better avoid joining with comma in the first place.

Production build 0.69.0 2024