Sending mails through SMTP settings in Magento

Why SMTP is required to deliver emails rather than normal server email:

Sometimes you might see your emails are being sent to Spam folder not in Inbox . It might be its an issue of your default mail settings which are not sending proper header or that server is blacklisted to deliver emails in that case SMTP might be a good option

By Default magento sends email from server itself which includes all emails like contacts email to transactional emails. If we want to use SMTP as our outgoing server then here are the steps to configure SMTP with Magento

Step 1: Login to magento Admin

Step 2: Go to System->Configuration->Advanced->System->Mail Sending Settings.

Step 3: Insert your SMTP host name and Port No.

Step 4: Copy  the file app/code/core/Mage/core/Model/Email/Template.php in your local folder so that we can override getMail() function

Override GetMail function in magento to deliver SMTP based email

Open your local folder and write and make certain changes to your getMail() . After your change your getMail() should look like

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’ => ’[email protected]’,
‘password’ => ‘yourpassword’                                               );
$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;
}

That’s it now your are done with your setup with SMTP in magento.

Note: Here its notable that only professional SMTP details (not regular like gmail or yahoo) gives good delivery rates . Because after doing these changes now SMTP is handeling all of your email related communication.

The following two tabs change content below.

Chandra Shekhar

GCP Architect
Chandra Shekhar Pandey is Google certified Cloud engineer, I am Magento2 Trained developer. Having huge experience in designing cloud solution. I have around 12 years of experience with world enterprise IT companies and fortune 500 clients. During my architecture design I am always caring about high availability, fast performance and resilient system. From the programmer background I have huge experience in LAMP stack as well. Throughout my carrier I have worked on Retail, E-Learning, Video Conferencing and social media domain. The motive of creating cutehits was just to share the knowledge/solutions I get to know during my day to day life so that if possible I can help someone for same problems/solutions. CuteHits.com is a really a very effort for sharing knowledge to rest of the world. For any query/suggestion about same you can contact me on below details:- Email: shekharmca2005 at gmail.com Phone: +91-9560201363

Latest posts by Chandra Shekhar (see all)

You may also like...