Skip to content

Fix deprecated preferred_mail_format

JonGold requested to merge JonGold/emailapi:deprecated-mail-format into master

Email API fails to send on CiviCRM 5.51+ with SMTP enabled.

Steps to replicate

  • Use a site that has email sending enabled - e.g. not a default buildkit site.
  • Set Outbound email to use SMTP, not mail().
  • Try sending an email via Email.send.

Expected Result

Email sends.

Actual result

{"code":null,"error_message":"Expected a string or file resource","mode":16,"debug_info":null,"type":"PEAR_Error","user_info":null,"to_string":"[pear_error: message=\"Expected a string or file resource\" code=0 mode=callback callback=CRM_Utils_REST::fatal prefix=\"\" info=\"\"]","is_error":1}

This happens because CiviCRM is phasing out support for preferred_mail_format. With PR 23565 it's no longer returned from the Contact.get API. This is causing Email.send to not attach any HTML or text to the email to be sent.

When sending via mail() there's some odd code path that causes this to get re-evaluated, but when sending via SMTP it fails because there's no body.

PR 23565 makes an almost identical change which you can compare to.

Merge request reports

Loading