Magento - How to enable SMTP server authentication and secure transport?

I want the SMTP server to work in the Magento application (version 1.7). so I added the following code to app/code/core/Mage/Core/Model/Email/Template.php

 public function getMail() { if (is_null($this->_mail)) { /*Start of added code to specify config*/ $my_smtp_host = Mage::getStoreConfig('system/smtp/host'); $my_smtp_port = Mage::getStoreConfig('system/smtp/port'); $config = array( 'ssl' => 'tls', 'port' => $my_smtp_port, 'auth' => 'login', 'username' => ' account@gmail.com ', 'password' => 'secret' ); $transport = new Zend_Mail_Transport_Smtp($my_smtp_host, $config); Zend_Mail::setDefaultTransport($transport); /*End of added code to specify config*/ $this->_mail = new Zend_Mail('utf-8'); } return $this->_mail; } 

Then in the Admin Panel-> System-> Configuration-> Advanced-> System-> Mail Sending Settings

The following settings are added

  • Host: smtp.gmail.com
  • Port (25): 587

After completing these changes, I checked (i.e. email to a friend) on the interface. A success message was shown, but the message was not in the mailbox (even in spam).

Hope someone can help me. I really appreciate it, thanks!

+4
source share
3 answers

You do not have to crack the core code, there are many reasons because it is NOT a good idea. One of them: you cannot update.

Instead, use the extension or write your own: http://www.magentocommerce.com/magento-connect/ASchroder/extension/1865/aschroder.com-smtp-pro

+9
source

I was able to send Forgot Password Email from localhost.

The only thing you need to do is follow the steps below and do it.

  • Edit this page app/code/core/Mage/Core/Model/Email/Template.php

Comment on the existing functionality and add the code below

  public function getMail() { if (is_null($this->_mail)) { /* changes begin */ $my_smtp_host = Mage::getStoreConfig('system/smtp/host'); $my_smtp_port = Mage::getStoreConfig('system/smtp/port'); $config = array( 'port' => $my_smtp_port, 'auth' => 'login', 'username' => 'your username', 'password' => 'your password' ); $transport = new Zend_Mail_Transport_Smtp($my_smtp_host, $config); Zend_Mail::setDefaultTransport($transport); /* Changes End */ $this->_mail = new Zend_Mail('utf-8'); } return $this->_mail; } 
  1. Go to admin System -> Configuration -> Advanced -> System -> Mail Sending settings and set the following things.

    Disable Email Communication = No

    Host = smtp.mandrillapp.com

    Port (25) = 587

    Set Return-Path = No

enter image description here

  1. Log in to admin System -> Transactional Emails -> Add New Template

    • In Download default template - select the required template, for example, 'Forgot Password' , and click Load Template . The default template will be populated in the template content.

    • In the template information - enter any name for the template, for example Forgot Password , and click on the save template.

  2. Log in to admin System -> Configuration -> Customers -> Customer Configuration -> Password Options

    • In the Forgot Email Template select "Forgot Password" (which was created in Transactional Emails) from the drop-down list.

    • Select Remind Email Template in "Forgot Password"

    • Select Forgot and Remind Email Sender for any dropdown value for ex - customer support.

enter image description here

Note. Verify that your customer support is set to the correct email address. To change the email address for customer support - Log in to admin System -> Configuration -> General -> Store email Address -> Customer support add a valid email address.

That is all you have done. Please feel free to post your inquiries. For more information, see http://pravams.com/2011/07/30/magento-send-email-using-smtp/

+3
source

Magento Mail transport is configured and made of these two functions

  • Mage_Core_Model_Email_Template -> send()
  • Mage_Newsletter_Model_Template -> send()

Here is the work module code that I created to send transactional emails through our email service provider. It overwrites Mage_Core_Model_Email_Template -> send()

Please note that you will need to hard-code additional configuration items for your purposes, as this code sample does not have settings for adding fields to the system configuration, but it should give you an idea of ​​how the send () function should be changed to using an SMTP server that requires authentication and can provide secure SSL / TLS transport.

 public function send($email, $name = null, array $variables = array()) { if (!$this->isValidForSend()) { Mage::logException(new Exception('This letter cannot be sent.')); // translation is intentionally omitted return false; } /* Set up mail transport to Email Hosting Provider SMTP Server via SSL/TLS */ $config = array( 'ssl' => Mage::getStoreConfig('system/smtp/ssl'), // option of none, ssl or tls 'port' => Mage::getStoreConfig('system/smtp/port'), // TLS 587 - SSL 465 - default 25 'auth' => Mage::getStoreConfig('system/smtp/auth'), // Auth type none, login, plain, CRAM-MD5 'username' => Mage::getStoreConfig('system/smtp/username'), 'password' => Mage::getStoreConfig('system/smtp/password') ); /* Set up transport package to host */ $transport = new Zend_Mail_Transport_Smtp(Mage::getStoreConfig('system/smtp/host'), $config); /* End transport setup */ $emails = array_values((array)$email); $names = is_array($name) ? $name : (array)$name; $names = array_values($names); foreach ($emails as $key => $email) { if (!isset($names[$key])) { $names[$key] = substr($email, 0, strpos($email, '@')); } } $variables['email'] = reset($emails); $variables['name'] = reset($names); // ini_set('SMTP', Mage::getStoreConfig('system/smtp/host')); // ini_set('smtp_port', Mage::getStoreConfig('system/smtp/port')); $mail = $this->getMail(); $setReturnPath = Mage::getStoreConfig(self::XML_PATH_SENDING_SET_RETURN_PATH); switch ($setReturnPath) { case 1: $returnPathEmail = $this->getSenderEmail(); break; case 2: $returnPathEmail = Mage::getStoreConfig(self::XML_PATH_SENDING_RETURN_PATH_EMAIL); break; default: $returnPathEmail = null; break; } if ($returnPathEmail !== null) { $mailTransport = new Zend_Mail_Transport_Sendmail("-f".$returnPathEmail); Zend_Mail::setDefaultTransport($mailTransport); } foreach ($emails as $key => $email) { $mail->addTo($email, '=?utf-8?B?' . base64_encode($names[$key]) . '?='); } $this->setUseAbsoluteLinks(true); $text = $this->getProcessedTemplate($variables, true); if($this->isPlain()) { $mail->setBodyText($text); } else { $mail->setBodyHTML($text); } $mail->setSubject('=?utf-8?B?' . base64_encode($this->getProcessedTemplateSubject($variables)) . '?='); $mail->setFrom($this->getSenderEmail(), $this->getSenderName()); try { /* Send Transport, empty and log success */ $mail->send($transport); //transport object $this->_mail = null; Mage::log('Mailed to: ' . $this->getSenderEmail() . ' ' . $this->getSenderName() . ' ' .$this->getProcessedTemplateSubject($variables), null, 'email.log'); /* End */ } catch (Exception $e) { /* Or empty and log failure */ $this->_mail = null; Mage::log('Failure: ' . $e, null, 'email.log'); Mage::logException($e); return false; /* End */ } return true; } 
+2
source

All Articles