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

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
Google chrome to make web apps as powerful as native ones

Android Apps Feb 2nd, 2017

Google chrome to make web apps as powerful as native on...

Read more
4 Reasons to Choose Open source development platforms for web development

Web Sep 16th, 2016

4 Reasons to Choose Open source development platforms f...

Read more

INQUIRY

Let's get in touch

UNITED STATES

31236 Meadowview Square,
Delmar, DE 19940, USA

Sales: +1 667 771 6758

UNITED KINGDOM

13 Layton Road, Hounslow,
London, TW3 1YJ

Sales: +44 7404 607567

INDIA

2nd Floor, Sun Avenue One, Bhudarpura, Ayojan Nagar, Nr. Shyamal Cross Road, Ahmedabad, Gujarat-380006

Sales: +91 635-261-6164

For Project Inquiries

biolah

depo 25 bonus 25 to 5x

depo 25 bonus 25

depo 25 bonus 25

mndrmndr.com

bonusdeposit.net

https://www.greentourstanzania.com/wp-includes/customize/

https://temp1.novotest.biz/id/

depo 25 bonus 25

https://sumberjo-blitar.desa.id/images

https://sumberjo-blitar.desa.id/data

depo 25 bonus 25 to 5x

depo 25 bonus 25

https://www.greentourstanzania.com/wp-includes/js/product/

https://smpabbs.sch.id/gacor/100/

https://smpabbs.sch.id/gacor/bonus/

deposit 25 bonus 25

depo 25 bonus 25

bonus new member 100

https://ppdb.smk-kosgoro.sch.id/data/depo 25 bonus 25https://jesus.nouvellevie.com/wp-includes/images/Getoko.iddepo 25 bonus 25https://bonus-baru.s3.ap-southeast-1.amazonaws.com/link-daftar-slot-gacor.htmlhttps://bonus-baru.s3.ap-southeast-1.amazonaws.com/scatter-pink-paling-gacor.htmlhttps://worldlisteningproject.org/wp-includes/depo25bonus25/bonus new member 100depo 25 bonus 25