Solution to send mails from development systems/servers

Dec 31st, 2014

Solution to send mails from development systems/servers

I faced this issue many times when I had to test the mail feature in my projects. I then had to add SMTP library separately to check in different web based mails like Google Mail, Yahoo Mail, Outlook, etc. or need to upload the code to production servers where mails worked.

Mandrill (sends to any really account – preferred for UAT and Production systems) and Mailtrap (sends to single account for any email address – preferred for Development systems) provides a very good way to do this. With small changes in configuration of the server we can easily use this to send mails to any account without having SPAM issues.

Mandrill can also be a very useful tool to send mails in production if Client has budget or the number of mails are very limited. It provides tracking tools, graph and we can even configure BCC on all mails without changing code for debugging purpose.

Today, I will cover how to configure it in Postfix (Linux Ubuntu/CentOS/Amazon Linux) and XAMPP using Sendmail.

Installing Postfix

Installing Postfix is easy, just run this command as root:

Configuring in Postfix

Basically, you need to create a password file so that Postfix can authenticate to Gmail’s servers. You do this by creating a file named sasl_passwd in /etc/postfix. Replace smtp_user and smtp_passwd with their respective values.

Step 1A (Mandrill):
echo “smtp.mandrillapp.com    smtp_user:smtp_passwd” > /etc/postfix/sasl_passwd

Step 1B (Mailtrap):
echo “smtp.mandrillapp.com    smtp_user:smtp_passwd” > /etc/postfix/sasl_passwd

You then hash that file so that the password is not stored in clear text. This command will create a file named sasl_passwd.db in the /etc/postfix/ directory.

Step 2: postmap hash:/etc/postfix/sasl_passwd

After that is done, add these to the bottom of /etc/postfix/main.cf. This is assuming that your root certificates installed from openssl are located in /etc/pki/tls/certs/ca-bundle.crt.

Step 3A (Mandrill):

smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous

# Secure channel TLS with exact nexthop name match.
smtp_tls_security_level = secure
smtp_tls_mandatory_protocols = TLSv1
smtp_tls_mandatory_ciphers = high
smtp_tls_secure_cert_match = nexthop
smtp_tls_CAfile = /etc/pki/tls/certs/ca-bundle.crt
relayhost = smtp.mandrillapp.com:587

tep 3B (Mailtrap):

smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
relayhost = mailtrap.io:2525

After that is done, restart postfix:

Step 4: service postfix restart

Now test it to make sure it is working. Run this:

Step 5: mail email@domain

Fill in the subject, put something in the body and then type a . and hit enter.

If all went well, you should get an email at the email address you entered. If you do, you can delete the file that has the password.

Step 6: rm /etc/postfix/sasl_passwd

If it did not work, check the log to see what happened.

Step 7: tail /var/log/maillog

Everything should be good after you get everything set up, so enjoy your new SMTP relay with Mandrill or Mailtrap!

Configuring in XAMPP

To do the same in XAMPP, we need to add sendmail. We can get sandmail from http://www.glob.com.au/sendmail/sendmail.zip

Extract the zip inside XAMPP directory.

Open sendmail.ini and change the settings inside as below:

[sendmail]
#smtp_server=smtp.mandrillapp.com

smtp_server=mailtrap.io

#smtp_port=587

smtp_port=2525
error_logfile=error.log
debug_logfile=debug.log
auth_username=[Email address for Mandrillapp or Mailtrap username here]
auth_password=[API key for Mandrill or password for Mailtrap.io]
force_sender=
[Email address]

Open php.ini, uncomment sendmail_path and change the path to where you have extracted sendmail:

[mail function]
sendmail_path = “”C:xamppsendmailsendmail.exe” -t”

Hope this helps you to test your mails that you develop.

 

Comments are closed.

Let's Discuss Your Project

Get free consultation and let us know your project idea to turn
it into an amazing digital product.

Let’s talk

NEWS & BLOG

Related Blogs

How To Estimate Web App Development Cost In 2024 –  A Detailed Guide

Web Aug 6th, 2024

How To Estimate Web App Development Cost In 2024 –...

Read more
How to Build a Web App: 12-step Beginner’s Guide (2024)

Web Jul 9th, 2024

How to Build a Web App: 12-step Beginner’s Guide ...

Read more
Why Node.js is Perfect for Enterprise App Development platform ?

Node.js May 1st, 2020

Why Node.js is Perfect for Enterprise App Development p...

Read more

INQUIRY

Let's get in touch

UNITED STATES

31236 Meadowview Square,
Delmar,
DE 19940, USA

Sales: +1 (415) 230 0051

UNITED KINGDOM

13 Layton Road,
Hounslow,
London, TW3 1YJ

Sales: +44 7404 607567

INDIA

101, Kalasagar Shopping Hub, Sattadhar, Gujarat 380061

+91 999-894-5667

For Project Inquiries

Please enable JavaScript in your browser to complete this form.
emailsales@solutionanalysts.com emailinfo@solutionanalysts.com emailcareer@solutionanalysts.com skypebiz.solutionanalysts