I am using PepiPost mail service and I created custom mail system class for integrating PepiPost service. I can successfully send email from Drupal site. If a connection timeout 504 occurs during email sending process, email is not triggered how can I handle this scenairo. This is the code I used for email sending

class CustomMailSystem implements MailSystemInterface {

  public function format(array $message) {
    // Join message array.

      $message['body'] = implode("\n\n", $message['body']);
      return $message;

   * Implement mail method to send mail via Sendgrid.
   * @param array $message
   * @return bool
  public function mail(array $message) {
    $email = new Email();

    $data = array(
      'api_key'   =>  '****************',
      'recipients'    =>  $to
      'email_details' => array(
        'from'          =>  $from,
        'subject'       =>  $subject,
        'content'       =>  $body,

  try {
    $response = $email->sendJson( $data );

  catch(Exception $e){
      print 'Call failed due to unhandled exception/error('. $e->getMessage().')'."\n";

1 Answer 1


you should always use some or the other Mail Transfer Agent (MTA) like Postfix, which helps in managing queue in-case of emails getting lost

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.