About SMTP and Magento

I have written this article, because the discussion over at the Magento forum, had many different resolutions. I will show you only one that is tested, and works for me with Magento 1.2 and similar releases.

First off relying on an external mail server has advantages and disadvantages, you can read more here- using an external mail server vs. an internal mail server. With the following configuration, you’ll be able to send email and have it show up in the recipient’s inbox, rather than in the junk or spam mail.

The following is based on using GoDaddy’s mail settings. I personally don’t like GoDaddy, because their mail servers are unreliable; I can go on and on, but i won’t. I am showing this example with GoDaddy, because currently they are a popular hosting provider. - so let’s get started with setting this smtp thingy up.

Overview Magento Version:
  • 1.2.x and Similar
System:
  • Ubuntu Server (Linux)
Difficulty:
  • Easy
Modification:
  • Core files.
Note:
  • Don’t use a live site for testing.


Step 1. Configure Backend

Go to your Magento backend > Configuration > System> smtp> (don’t worry about windows stuff) type:
smtp.securecerver.net and 25 as the port

Step 2. Edit Core File

Go to your Magento installation/ app/ code/ core/ Mage/ Core/ Model/ Email/ Template.php file and…

Replace:

public function getMail()
    {
        if (is_null($this->_mail)) {
             $this->_mail = new Zend_Mail('utf-8');
        }
 return $this->_mail;
    }

With:

 public function getMail()
    {
        if (is_null($this->_mail)) {
 
		/*Start Hack*/
           $my_smtp_host = Mage::getStoreConfig('system/smtp/host');
           $my_smtp_port = Mage::getStoreConfig('system/smtp/port');
           $config = array(
                    'port' => $my_smtp_port, //optional - default 25
                    'auth' => 'login',
                    'username' => 'yourrelay@youremailhost.com',
                    'password' => 'youremailpassword'
                );
            $transport = new Zend_Mail_Transport_Smtp($my_smtp_host, $config);
            Zend_Mail::setDefaultTransport($transport);
            /*End Hack*/
 
            $this->_mail = new Zend_Mail('utf-8');
        }
        return $this->_mail;
    }

Testing

Go to front end and send your self an email (Tell a friend)- done. Now go and place an order on either the backend or the front -done. If these test all work, than boda bing, you have have a working Magento mail configuration.

Summary

By following the steps outlined above you will be sending mail with an external mail server, in no time.

SMTP Note: In order for your sent email to be recv’d in the recipient’s inbox, you must check your public server ip which is sending the email against spam filters such as spamhaus. And make sure everything is resolving correctly. You can visit my other article here, which discusses these issues and many more. Hack Note: This hack will modify core files, so keep a local log of the files you modify. What I do is keep folders and log each change accordingly. By naming one file to /mods/core, and the other to /mods/template and placing each mod into the corresponding folder.

This entry was posted on Saturday, January 24th, 2009 at 2:15 pm and is filed under Magento. You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.