Problem/Motivation

In Drupal 9.2.9 using SMTP version (1.0.0) when I try to connect to Amazon SES and try to programmatically send mail, I get the following error. Sending a SMTP test mail works fine from Drupal admin.

Error log - Error sending e-mail from xxxx to xxx@gmail.com: SMTP Error: data not accepted.SMTP server error: DATA END command failed Detail: Transaction failed: Expected ';', got "\" SMTP code: 554

2022-02-02 06:17:37 CLIENT -> SERVER: X-Mailer: PHPMailer 6.5.3 (https://github.com/PHPMailer/PHPMailer)
2022-02-02 06:17:37 CLIENT -> SERVER: Sender: xxxxxxxxx
2022-02-02 06:17:37 CLIENT -> SERVER: MIME-Version: 1.0
2022-02-02 06:17:37 CLIENT -> SERVER: Content-Type: text/html; charset=utf-8\n
2022-02-02 06:17:37 CLIENT -> SERVER: Content-Transfer-Encoding: 8Bit
2022-02-02 06:17:37 CLIENT -> SERVER:
2022-02-02 06:17:37 CLIENT -> SERVER: This is test message
2022-02-02 06:17:37 CLIENT -> SERVER:
2022-02-02 06:17:37 CLIENT -> SERVER:
2022-02-02 06:17:37 CLIENT -> SERVER: .
2022-02-02 06:17:37 SMTP INBOUND: "554 Transaction failed: Expected ';', got "\""
2022-02-02 06:17:37 SERVER -> CLIENT: 554 Transaction failed: Expected ';', got "\"
2022-02-02 06:17:37 SMTP ERROR: DATA END command failed: 554 Transaction failed: Expected ';', got "\"
SMTP Error: data not accepted.

This is code I am using.

$mail_manager = \Drupal::service('plugin.manager.mail');
$result = $mail_manager->mail($module_name, $key, $recipients, $langcode, $params, $reply, true);

Steps to reproduce

This is the SMTP configuration.

  • SMTP port: 587
  • Use TLS
  • Timeout: 30

Comments

jayat27 created an issue. See original summary.

avpaderno’s picture

Version: 9.2.x-dev » 9.4.x-dev
Issue summary: View changes

Bugs are first fixed on the 9.4.x branch; eventually, the fix is back-ported.

avpaderno’s picture

Title: Issue in sending SMTP mail via AWS programmatically » Issue in programmatically sending emails via AWS
Project: Drupal core » PHPMailer SMTP
Version: 9.4.x-dev » 2.1.x-dev
Component: mail system » Code

In a plain Drupal installation, the class used to send emails is PhpMail, which uses the mail() function implemented by PHP to send emails, not the PHPMailer library.

It seems you are using the PHPMailer SMTP module.

avpaderno’s picture

The code that could cause that issue is in PhpMailerSmtp::mail(), but since it uses trim(), it removes any trailing new line character.

      // Extract Content-Type and charset.
      if (isset($headers['content-type'])) {
        $content_type = explode(';', $headers['content-type']);
        $this->ContentType = trim(array_shift($content_type));
        foreach ($content_type as $param) {
          $param = explode('=', $param, 2);
          $key = trim($param[0]);
          if ($key == 'charset') {
            $this->CharSet = trim($param[1]);
          }
          else {
            $this->ContentType .= '; ' . $key . '=' . trim($param[1]);
          }
        }
        unset($headers['content-type']);
      }
imclean’s picture

Project: PHPMailer SMTP » SMTP Authentication Support
Version: 2.1.x-dev » 8.x-1.x-dev

In Drupal 9.2.9 using SMTP version (1.0.0)

I think this is the SMTP Auth module, which also uses the PHPMailer library.

imclean’s picture

But in response to #4, I don't think the trim() is a problem. The properties are used by the PHPMailer library which adds the appropriate separators or newlines as required.

imclean’s picture

I misread #4. Ignore my comment #6.

bluegeek9’s picture

Category: Bug report » Support request
Status: Active » Closed (works as designed)
It seems you are using the PHPMailer SMTP module.

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

bluegeek9’s picture

Status: Closed (works as designed) » Fixed
//www.flaticon.com/free-icons/thank-you Thank you for your contribution! Your continued support makes this project sustainable.
There are multiple ways to show appreciation for the work contributed to this project including:
  • Triage issues and adding more context to existing issues.
  • Flagging SMTP as a favorite on the project page to help others discover it and show your support.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.