Tag Archives: email

Sending mails from a Zend application

If you are making an application that needs to send out e-mails to for example hundreds of your users, then you don’t really want to actually send them e-mails when testing your application in a development environment. They would totally not appreciate getting multiples of your test e-mails, probably littered with loads of debugging code.

However, in Zend Framework you can have a different configuration for your development environment. One of these configuration items is the mail transport system. If you tell Zend to use the following for your development environment:

resources.mail.transport.type = Zend_Mail_Transport_File
resources.mail.transport.path = APPLICATION_PATH "/../mails"

then the Zend Framework will put all e-mails sent using the Zend_Mail class, in this mails directory in your project’s root directory. This way, you can safely test all the out-going e-mails that are sent by your application, and check them out in the mails directory.

There is still one more thing to do. If you do the above, you will notice that Zend creates *.tmp files that are in a certain ugly MIME encoding format (7bit, quoted-printable or base64). What is more, you will have a hard time checking the HTML layout of your HTML e-mails, since you’ll only see HTML code in the *.tmp files for your HTML e-mails, which are also encoded in the aforementioned ugly mail encoding.

Add mutt to your toolkit, configure your Zend mail transport to put the mails in the new directory of the mutt tree, and you’ll be able to access your e-mails using mutt!

First the Zend configuration:

resources.mail.transport.type = Zend_Mail_Transport_File
resources.mail.transport.path = APPLICATION_PATH "/../mails/new"

Then install mutt and prepare the directories:

sudo apt-get install mutt
mkdir -p mails/tmp mails/cur mails/new
chgrp www-data mails/new
chmod g+w mails/new

Start mutt, telling it to use the mails directory:

mutt -f mails

And there you go, you’ll be able to see incoming mails, sent from your Zend application. No need to fiddle with the addTo() calls that could be everywhere.

To check the HTML version in your mutt e-mail client, open the e-mail, hit v to see the attachments, navigate to the text/html part, hit Enter, and mutt will open it in your default web browser.