Thank you for your feedback, unfortunatelly I had no luch with it. Swift Mailer throws me an error message: Connection could not be established with host smtp.hubapi.com. Any idea what could be the reson?
Thanks for sharing that. Unfortunately, I don't think it gets us any closer to a solution.
Per this post in the other thread, could you share a snippet of the code you're using to configure SwiftMailer? Also, could you confirm the version you're using?
Once again thank you for your help. The appication we develope is build with Drupal 8. To send an email we use Swift Mailer module (https://www.drupal.org/project/swiftmailer) and it works fine when I use google smtp for example. This is the module function that sends an email and bellow values of the variables:
public function mail(array $message) {
try {
// Create a new message.
$m = Swift_Message::newInstance();
// Not all Drupal headers should be added to the e-mail message.
// Some headers must be suppressed in order for Swift Mailer to
// do its work properly.
$suppressable_headers = swiftmailer_get_supressable_headers();
// Keep track of whether we need to respect the provided e-mail
// format or not.
$respect_format = $this->config['message']['respect_format'];
// Process headers provided by Drupal. We want to add all headers which
// are provided by Drupal to be added to the message. For each header we
// first have to find out what type of header it is, and then add it to
// the message as the particular header type.
if (!empty($message['headers']) && is_array($message['headers'])) {
foreach ($message['headers'] as $header_key => $header_value) {
// Check wether the current header key is empty or represents
// a header that should be suppressed. If yes, then skip header.
if (empty($header_key) || in_array($header_key, $suppressable_headers)) {
continue;
}
// Skip 'Content-Type' header if the message to be sent will be a
// multipart message or the provided format is not to be respected.
if ($header_key == 'Content-Type' && (!$respect_format || swiftmailer_is_multipart($message))) {
continue;
}
// Get header type.
$header_type = Conversion::swiftmailer_get_headertype($header_key, $header_value);
// Add the current header to the e-mail message.
switch ($header_type) {
case SWIFTMAILER_HEADER_ID:
Conversion::swiftmailer_add_id_header($m, $header_key, $header_value);
break;
case SWIFTMAILER_HEADER_PATH:
Conversion::swiftmailer_add_path_header($m, $header_key, $header_value);
break;
case SWIFTMAILER_HEADER_MAILBOX:
Conversion::swiftmailer_add_mailbox_header($m, $header_key, $header_value);
break;
case SWIFTMAILER_HEADER_DATE:
Conversion::swiftmailer_add_date_header($m, $header_key, $header_value);
break;
case SWIFTMAILER_HEADER_PARAMETERIZED:
Conversion::swiftmailer_add_parameterized_header($m, $header_key, $header_value);
break;
default:
Conversion::swiftmailer_add_text_header($m, $header_key, $header_value);
break;
}
}
}
// Set basic message details.
Conversion::swiftmailer_remove_header($m, 'From');
Conversion::swiftmailer_remove_header($m, 'To');
Conversion::swiftmailer_remove_header($m, 'Subject');
// Parse 'from' and 'to' mailboxes.
$from = Conversion::swiftmailer_parse_mailboxes($message['from']);
$to = Conversion::swiftmailer_parse_mailboxes($message['to']);
// Set 'from', 'to' and 'subject' headers.
$m->setFrom($from);
$m->setTo($to);
$m->setSubject($message['subject']);
// Get applicable format.
$applicable_format = $this->getApplicableFormat($message);
// Get applicable character set.
$applicable_charset = $this->getApplicableCharset($message);
// Set body.
$m->setBody($message['body'], $applicable_format, $applicable_charset);
// Add alternative plain text version if format is HTML and plain text
// version is available.
if ($applicable_format == SWIFTMAILER_FORMAT_HTML && !empty($message['plain'])) {
$m->addPart($message['plain'], SWIFTMAILER_FORMAT_PLAIN, $applicable_charset);
}
// Validate that $message['params']['files'] is an array.
if (empty($message['params']['files']) || !is_array($message['params']['files'])) {
$message['params']['files'] = array();
}
// Let other modules get the chance to add attachable files.
$files = $this->moduleHandler->invokeAll('swiftmailer_attach', array('key' => $message['key'], 'message' => $message));
if (!empty($files) && is_array($files)) {
$message['params']['files'] = array_merge(array_values($message['params']['files']), array_values($files));
}
// Attach files.
if (!empty($message['params']['files']) && is_array($message['params']['files'])) {
$this->attach($m, $message['params']['files']);
}
// Attach files (provide compatibility with mimemail)
if (!empty($message['params']['attachments']) && is_array($message['params']['attachments'])) {
$this->attachAsMimeMail($m, $message['params']['attachments']);
}
// Embed images.
if (!empty($message['params']['images']) && is_array($message['params']['images'])) {
$this->embed($m, $message['params']['images']);
}
static $mailer;
// If required, create a mailer which will be used to send the message.
if (empty($mailer)) {
// Get the configured transport type.
$transport_type = $this->config['transport']['transport'];
// Configure the mailer based on the configured transport type.
switch ($transport_type) {
case SWIFTMAILER_TRANSPORT_SMTP:
// Get transport configuration.
$host = $this->config['transport']['smtp_host'];
$port = $this->config['transport']['smtp_port'];
$encryption = $this->config['transport']['smtp_encryption'];
$username = $this->config['transport']['smtp_username'];
$password = $this->config['transport']['smtp_password'];
// Instantiate transport.
$transport = Swift_SmtpTransport::newInstance($host, $port);
$transport->setLocalDomain('[127.0.0.1]');
// Set encryption (if any).
if (!empty($encryption)) {
$transport->setEncryption($encryption);
}
// Set username (if any).
if (!empty($username)) {
$transport->setUsername($username);
}
// Set password (if any).
if (!empty($password)) {
$transport->setPassword($password);
}
$mailer = Swift_Mailer::newInstance($transport);
break;
case SWIFTMAILER_TRANSPORT_SENDMAIL:
// Get transport configuration.
$path = $this->config['transport']['sendmail_path'];
$mode = $this->config['transport']['sendmail_mode'];
// Instantiate transport.
$transport = Swift_SendmailTransport::newInstance($path . ' -' . $mode);
$mailer = Swift_Mailer::newInstance($transport);
break;
case SWIFTMAILER_TRANSPORT_NATIVE:
// Instantiate transport.
$transport = Swift_MailTransport::newInstance();
$mailer = Swift_Mailer::newInstance($transport);
break;
case SWIFTMAILER_TRANSPORT_SPOOL:
// Instantiate transport.
$spooldir = $this->config['transport']['spool_directory'];
$spool = new Swift_FileSpool($spooldir);
$transport = Swift_SpoolTransport::newInstance($spool);
$mailer = Swift_Mailer::newInstance($transport);
break;
}
}
// Send the message.
Conversion::swiftmailer_filter_message($m);
return $mailer->send($m);
}
catch (Exception $e) {
$headers = !empty($m) ? $m->getHeaders() : '';
$headers = !empty($headers) ? nl2br($headers->toString()) : 'No headers were found.';
$this->logger->error(
'An attempt to send an e-mail message failed, and the following error
message was returned : @exception_message<br /><br />The e-mail carried
the following headers:<br /><br />@headers',
array('@exception_message' => $e->getMessage(), '@headers' => $headers));
drupal_set_message(t('An attempt to send an e-mail message failed.'), 'error');
}
}