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.
- 1.2.x and Similar
- Ubuntu Server (Linux)
- Easy
- Core files.
- 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.


















" Setup smtp with Magento "
Hi,
You can use my open source extension to do this, no hacking needed, get it for free on Magento connect here: http://www.magentocommerce.com/extension/1865. You can read more about it here: http://www.aschroder.com/2009/08/magento-smtp-pro-extension-free-smtp-support/
Also, just a quick tip, if you _are_ hacking files, you should do it by copying the core file to the local code base, and make the changes there, then when you upgrade Magento it won’t hose your hacks and it makes diffing changes easier.
" Setup smtp with Magento "
Hi,
I really liked your blog! you are a very talented person
Regards,
Viny
" Setup smtp with Magento "
Nice information on Magento and SMTP, Thank you for provide code for it. keep writing.