{"id":20211,"date":"2014-12-31T08:35:46","date_gmt":"2014-12-31T14:05:46","guid":{"rendered":"https:\/\/www.solutionanalysts.com\/blog\/solution-to-send-mails-from-development-systems-servers\/"},"modified":"2023-08-16T23:00:45","modified_gmt":"2023-08-17T04:30:45","slug":"solution-to-send-mails-from-development-systemsservers","status":"publish","type":"post","link":"https:\/\/www.solutionanalysts.com\/blog\/solution-to-send-mails-from-development-systemsservers\/","title":{"rendered":"Solution to send mails from development systems\/servers"},"content":{"rendered":"<p>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.<\/p>\n<p>Mandrill (sends to any really account &#8211; preferred for UAT and Production systems) and <a href=\"https:\/\/mailtrap.io\/\" data-blogger-escaped-rel=\"nofollow\" data-blogger-escaped-target=\"_blank\" target=\"_blank\" rel=\"noopener\">Mailtrap<\/a> (sends to single account for any email address &#8211; 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.<\/p>\n<p>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.<\/p>\n<p>Today, I will cover how to configure it in Postfix (Linux Ubuntu\/CentOS\/Amazon Linux) and XAMPP using Sendmail.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Installing_Postfix\"><\/span>Installing Postfix<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<div style=\"text-align: left;\">\n<p>Installing Postfix is easy, just run this command as root:<\/p>\n<\/div>\n<h3 style=\"text-align: left;\"><span class=\"ez-toc-section\" id=\"Configuring_in_Postfix\"><\/span>Configuring in Postfix<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Basically, you need to create a password file so that Postfix can authenticate to Gmail&#8217;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.<\/p>\n<p>Step 1A (Mandrill):<br \/>\necho &#8220;smtp.mandrillapp.com\u00a0\u00a0\u00a0 smtp_user:smtp_passwd&#8221; &gt; \/etc\/postfix\/sasl_passwd<\/p>\n<p>Step 1B (Mailtrap):<br \/>\necho &#8220;smtp.mandrillapp.com\u00a0\u00a0\u00a0 smtp_user:smtp_passwd&#8221; &gt; \/etc\/postfix\/sasl_passwd<\/p>\n<p>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.<\/p>\n<p>Step 2: postmap hash:\/etc\/postfix\/sasl_passwd<\/p>\n<p>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.<\/p>\n<p>Step 3<span style=\"font-family: 'Courier New',Courier,monospace; font-size: medium;\"><span style=\"font-family: 'Courier New',Courier,monospace;\">A (Mandrill)<\/span>:<\/span><\/p>\n<p>smtp_sasl_auth_enable = yes<br \/>\nsmtp_sasl_password_maps = hash:\/etc\/postfix\/sasl_passwd<br \/>\nsmtp_sasl_security_options = noanonymous<\/p>\n<p># Secure channel TLS with exact nexthop name match.<br \/>\nsmtp_tls_security_level = secure<br \/>\nsmtp_tls_mandatory_protocols = TLSv1<br \/>\nsmtp_tls_mandatory_ciphers = high<br \/>\nsmtp_tls_secure_cert_match = nexthop<br \/>\nsmtp_tls_CAfile = \/etc\/pki\/tls\/certs\/ca-bundle.crt<br \/>\nrelayhost = smtp.mandrillapp.com:587<\/p>\n<p>tep 3B (Mailtrap):<\/p>\n<p>smtp_sasl_auth_enable = yes<br \/>\nsmtp_sasl_password_maps = hash:\/etc\/postfix\/sasl_passwd<br \/>\nsmtp_sasl_security_options = noanonymous<br \/>\nrelayhost = mailtrap.io:2525<\/p>\n<p><span style=\"font-family: Georgia,'Times New Roman',serif; font-size: medium;\">After that is done, restart postfix:<\/span><\/p>\n<p><span style=\"font-family: 'Courier New',Courier,monospace; font-size: medium;\">Step 4: service postfix restart<\/span><\/p>\n<p><span style=\"font-family: Georgia,'Times New Roman',serif; font-size: medium;\">Now test it to make sure it is working. Run this:<\/span><\/p>\n<p><span style=\"font-family: 'Courier New',Courier,monospace; font-size: medium;\">Step 5: mail email@domain<\/span><\/p>\n<p><span style=\"font-family: Georgia,'Times New Roman',serif; font-size: medium;\">Fill in the subject, put something in the body and then type a . and hit enter.<\/span><\/p>\n<p><span style=\"font-family: Georgia,'Times New Roman',serif; font-size: medium;\">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.<\/span><\/p>\n<p><span style=\"font-family: 'Courier New',Courier,monospace; font-size: medium;\">Step 6: rm \/etc\/postfix\/sasl_passwd<\/span><\/p>\n<p><span style=\"font-family: Georgia,'Times New Roman',serif; font-size: medium;\">If it did not work, check the log to see what happened.<\/span><\/p>\n<p><span style=\"font-family: 'Courier New',Courier,monospace; font-size: medium;\">Step 7: tail \/var\/log\/maillog<\/span><\/p>\n<p><span style=\"font-family: Georgia,'Times New Roman',serif; font-size: medium;\">Everything should be good after you get everything set up, so enjoy your new SMTP relay with <a href=\"https:\/\/mandrillapp.com\/login\/?referrer=%2F\" target=\"_blank\" rel=\"noopener\">Mandrill<\/a> or <\/span><span style=\"font-family: Georgia,'Times New Roman',serif; font-size: medium;\"><span style=\"font-family: Georgia,'Times New Roman',serif;\"><a href=\"https:\/\/mailtrap.io\/\" data-blogger-escaped-rel=\"nofollow\" data-blogger-escaped-target=\"_blank\" target=\"_blank\" rel=\"noopener\">Mailtrap<\/a><\/span>!<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Configuring_in_XAMPP\"><\/span><span style=\"font-family: Georgia,'Times New Roman',serif; font-size: medium;\">Configuring in XAMPP<\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-family: 'Courier New',Courier,monospace; font-size: medium;\"><span style=\"font-family: Georgia,'Times New Roman',serif;\">To do the same in XAMPP, we need to add sendmail. We can get sandmail from <a href=\"http:\/\/www.glob.com.au\/sendmail\/sendmail.zip\" data-blogger-escaped-rel=\"nofollow\" data-blogger-escaped-target=\"_blank\" target=\"_blank\" rel=\"noopener\">http:\/\/www.glob.com.au\/sendmail\/sendmail.zip<\/a><\/span><\/span><\/p>\n<p><span style=\"font-family: 'Courier New',Courier,monospace; font-size: medium;\"><span style=\"font-family: Georgia,'Times New Roman',serif;\">Extract the zip inside XAMPP directory.<\/span><\/span><\/p>\n<p>Open sendmail.ini and change the settings inside as below:<\/p>\n<p><span style=\"font-family: 'Courier New',Courier,monospace;\">[sendmail]<br \/>\n#smtp_server=smtp.mandrillapp.com<\/span><\/p>\n<p><span style=\"font-family: 'Courier New',Courier,monospace; font-size: medium;\"><span style=\"font-family: Georgia,'Times New Roman',serif;\"><span style=\"font-family: 'Courier New',Courier,monospace;\"><span style=\"font-family: 'Courier New',Courier,monospace;\"><span style=\"font-family: Georgia,'Times New Roman',serif;\"><span style=\"font-family: 'Courier New',Courier,monospace;\">smtp_server=mailtrap.io<\/span><\/span><\/span><\/span><\/span><\/span><\/p>\n<p><span style=\"font-family: 'Courier New',Courier,monospace; font-size: medium;\"><span style=\"font-family: Georgia,'Times New Roman',serif;\"><span style=\"font-family: 'Courier New',Courier,monospace;\">#smtp_port=587<\/span><\/span><\/span><\/p>\n<p><span style=\"font-family: 'Courier New',Courier,monospace; font-size: medium;\"><span style=\"font-family: Georgia,'Times New Roman',serif;\"><span style=\"font-family: 'Courier New',Courier,monospace;\">smtp_port=2525<br \/>\nerror_logfile=error.log<br \/>\ndebug_logfile=debug.log<br \/>\nauth_username=[Email address for Mandrillapp or Mailtrap username here]<br \/>\nauth_password=[API key for Mandrill or password for Mailtrap.io]<br \/>\nforce_sender=<\/span><\/span><\/span><span style=\"font-family: 'Courier New',Courier,monospace; font-size: medium;\"><span style=\"font-family: Georgia,'Times New Roman',serif;\"><span style=\"font-family: 'Courier New',Courier,monospace;\">[Email address]<\/span><\/span><\/span><\/p>\n<p><span style=\"font-family: Georgia,'Times New Roman',serif; font-size: medium;\">Open php.ini, uncomment sendmail_path and change the path to where you have extracted sendmail:<\/span><\/p>\n<p><span style=\"font-size: medium;\"><span style=\"font-family: 'Courier New',Courier,monospace;\">[mail function]<\/span><\/span><br \/>\n<span style=\"font-size: medium;\"><span style=\"font-family: 'Courier New',Courier,monospace;\">sendmail_path = &#8220;&#8221;C:xamppsendmailsendmail.exe&#8221; -t&#8221;<\/span><\/span><\/p>\n<p><span style=\"font-family: Georgia,'Times New Roman',serif; font-size: medium;\">Hope this helps you to test your mails that you develop.<\/span><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I faced this issue many times when I had to test the mail feature in my projects. I then had<\/p>\n","protected":false},"author":1,"featured_media":37322,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[129],"tags":[],"class_list":["post-20211","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-web"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.solutionanalysts.com\/blog\/wp-json\/wp\/v2\/posts\/20211","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.solutionanalysts.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.solutionanalysts.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.solutionanalysts.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.solutionanalysts.com\/blog\/wp-json\/wp\/v2\/comments?post=20211"}],"version-history":[{"count":2,"href":"https:\/\/www.solutionanalysts.com\/blog\/wp-json\/wp\/v2\/posts\/20211\/revisions"}],"predecessor-version":[{"id":37317,"href":"https:\/\/www.solutionanalysts.com\/blog\/wp-json\/wp\/v2\/posts\/20211\/revisions\/37317"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.solutionanalysts.com\/blog\/wp-json\/wp\/v2\/media\/37322"}],"wp:attachment":[{"href":"https:\/\/www.solutionanalysts.com\/blog\/wp-json\/wp\/v2\/media?parent=20211"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.solutionanalysts.com\/blog\/wp-json\/wp\/v2\/categories?post=20211"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.solutionanalysts.com\/blog\/wp-json\/wp\/v2\/tags?post=20211"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}