{"id":1100,"date":"2011-12-12T17:03:11","date_gmt":"2011-12-12T15:03:11","guid":{"rendered":"http:\/\/blog.railsware.com\/?p=1100"},"modified":"2021-08-13T16:24:16","modified_gmt":"2021-08-13T13:24:16","slug":"mailtrap-save-your-customers-from-getting-test-emails","status":"publish","type":"post","link":"https:\/\/railsware.com\/blog\/mailtrap-save-your-customers-from-getting-test-emails\/","title":{"rendered":"Mailtrap: Save your customers from getting test emails."},"content":{"rendered":"\n<p>We assume you&#8217;re a web <a href=\"https:\/\/railsware.com\/careers\/\">developer<\/a>, QA engineer, product manager, etc \u2014 somebody who&#8217;s doing internet software projects. Have you ever needed to test e-mail notifications in your web application? Today we&#8217;ll speak about common issues while testing e-mail notifications and best solutions for that issues.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Common issues with manual e-mail notifications testing<\/h3>\n\n\n\n<p>We believe most critical issue here is accidentally sending dummy e-mails to real customers while testing web applications at staging\/development servers. But let&#8217;s start with easier once at first.<\/p>\n\n\n\n<p>Let&#8217;s say you&#8217;re doing users registration where every new users gets registration confirmation e-mail. In order to register yet another user for testing purposes you need to have new unique email address that should be registered somewhere. That&#8217;ll become problematic unless you&#8217;ll use service like <a href=\"http:\/\/mailinator.com\/\">Mailinator<\/a> which seems good enough as a solution for our problem.<\/p>\n\n\n\n<p>Now let&#8217;s make things a bit harder. Imagine our web application became successful and now we need to send weekly e-mail notifications to our users: a bit different for different users. How will you test that to know which e-mails were sent to which customers? Will you create tons of virtual users with tons of mail boxes and check each one? But that&#8217;s just so stupid and time-consuming!<\/p>\n\n\n\n<p>In real life things are even worse. In my experience it is usually a good idea to copy production database to your staging servers or development machines for test purposes \u2014 so you&#8217;ll work with a real data instead of something synthetic. But this also brings you a risk of sending test e-mails to the real customers from your development\/staging environment. My personal score is about 2500 e-mails sent by mistake at a time. I know people whose personal record is <em>more than 2 millions emails sent by mistake!<\/em> Share your personal fuck up stories in comments ;)<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Existing solutions for keeping your customers from test e-mails<\/h3>\n\n\n\n<p>If you&#8217;re lazy or just don&#8217;t have enough time, you may skip this chapter and just scroll down to <em>Mailtrap: our solution to common problem<\/em> because our solution is really much better that others, believe me!<\/p>\n\n\n\n<p>So which possible solutions are most popular?<br><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Tweaking up your SMTP server, so it&#8217;ll send all messages based on specific rules, for example will rewrite recipient e-mail address to yours one. We used this solution for sending all e-mails to whole development team for one of our projects. It was fine but there was just one problem: each team member got tens to hundreds e-mails in his mailbox each time our QA engineers checked new application release. And what if you don&#8217;t have access to SMTP server settings?<\/li><li>Stripping customer e-mails from your test database with a special script, etc. In this case you&#8217;ll still need to have lots of test mailboxes which is quite a drawback, but you&#8217;ll be safe: real customers won&#8217;t get test e-mails from you.<\/li><li>Use dummy SMTP servers that&#8217;ll save all e-mails messages locally instead of sending them. <a href=\"http:\/\/rubygems.org\/gems\/mailcatcher\">Mailcatcher<\/a> is a good example of such tool for Ruby. You can easily find same tools built with PHP, Python, etc. One major disadvantage on all of these tools is that they&#8217;re assumed to work on developer&#8217;s machine (so you can access that saved e-mails anytime), not on the staging servers where most non-developers test application functionality.<\/li><li>Some teams even prefer hardcoding different application logic for different environments. For example application will send e-mails normally from production servers but will forward it to special e-mail addresses for all e-mails other that @your-domain.com. This solution may be more flexible than previous 3 but also harder to implement and support.<\/li><\/ul>\n\n\n\n<p>As you can see each solution have major disadvantages. That&#8217;s the reason we&#8217;ve created an alternative one called Mailtrap.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Mailtrap: our solution to common problem<\/h3>\n\n\n\n<p><a href=\"https:\/\/mailtrap.io\">Mailtrap<\/a> is a standardized solution aimed to help development teams to build and debug their email delivery functionality: it substitutes your SMTP server and allows viewing all your e-mails online at Mailtrap site, forward them to your normal mailbox if needed.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"565\" height=\"316\" src=\"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2011\/12\/mtr.png\" alt=\"\" class=\"wp-image-1136\" title=\"mtr\" srcset=\"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2011\/12\/mtr.png 565w, https:\/\/railsware.com\/blog\/wp-content\/uploads\/2011\/12\/mtr-300x167.png 300w\" sizes=\"auto, (max-width: 565px) 100vw, 565px\" \/><\/figure><\/div>\n\n\n\n<p>So how does it work? You get Mailtrap&#8217;s SMTP credentials after registration. Than all you need to do is placing those credentials (hostname, port, login and password) to your application&#8217;s configuration (for non-production environments)&#8230; and Voil\u00e0 \u2014 your e-mails sending is isolated from real users but still available to view and forward!<\/p>\n\n\n\n<p>Ruby on Rails setup example.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">config.action_mailer.smtp_settings = {\n    :address =&gt; 'mailtrap.io',\n    :port =&gt; 2525,\n    :user_name =&gt; 'box52',\n    :password =&gt; '133632a53ddfec53a4b05496f7296a60'\n\n}<\/pre>\n\n\n\n<p>No local daemons setup, no tweaks on your staging server, no application-level modifications \u2014 just change 4 lines of code, that&#8217;s it!<br>Since Mailtrap uses standard SMTP protocol it is cross-platform: you&#8217;re able use it with any platform on any programming language.<\/p>\n\n\n\n<p>All e-mails are now available to view at mailtrap.io. Each e-mail has unique URL \u2014 so you can share it with your team members with no problem while creating new bug tickets in your issue tracker, for example.<br>For some cases we have alternative solution(for example, you&#8217;d like to see how your e-mail messages look in specific mail client): you can forward a message to specific e-mail address directly from Mailtrap&#8217;s web interface.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"132\" src=\"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2011\/12\/mtr_1-300x132.jpg\" alt=\"\" class=\"wp-image-1145\" title=\"mtr_1\" srcset=\"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2011\/12\/mtr_1-300x132.jpg 300w, https:\/\/railsware.com\/blog\/wp-content\/uploads\/2011\/12\/mtr_1-1024x452.jpg 1024w, https:\/\/railsware.com\/blog\/wp-content\/uploads\/2011\/12\/mtr_1.jpg 1275w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"132\" src=\"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2011\/12\/mtr_21-300x132.jpg\" alt=\"\" class=\"wp-image-1149\" title=\"mtr_2\" srcset=\"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2011\/12\/mtr_21-300x132.jpg 300w, https:\/\/railsware.com\/blog\/wp-content\/uploads\/2011\/12\/mtr_21-1024x453.jpg 1024w, https:\/\/railsware.com\/blog\/wp-content\/uploads\/2011\/12\/mtr_21.jpg 1279w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/figure><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">Are there any bells and whistles there?<\/h4>\n\n\n\n<p>Yes, here is a quick list of current Mailtrap features:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Ability to access ANY e-mail without registration<\/li><li>Sharing e-mail by copy&#8217;n&#8217;pasting its URL<\/li><li>Developer tools for debugging &amp; improving email templates which include HTML syntax highlighter, message source code view, CSS reseting.<\/li><li>Access to messages history.<\/li><\/ul>\n\n\n\n<p>And yes, it is completely free!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We assume you&#8217;re a web developer, QA engineer, product manager, etc \u2014 somebody who&#8217;s doing internet software projects. Have you ever needed to test e-mail notifications in your web application? Today we&#8217;ll speak about common issues while testing e-mail notifications and best solutions for that issues. Common issues with manual e-mail notifications testing We believe&#8230;<\/p>\n","protected":false},"author":1,"featured_media":7466,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[364],"tags":[],"coauthors":["admin"],"class_list":["post-1100","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-labs"],"acf":[],"aioseo_notices":[],"categories_data":[{"name":"Labs","link":"https:\/\/railsware.com\/blog?category=labs"}],"post_thumbnails":"https:\/\/railsware.com\/blog\/wp-content\/uploads\/2011\/12\/mtr.png","amp_enabled":true,"_links":{"self":[{"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/posts\/1100","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/comments?post=1100"}],"version-history":[{"count":56,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/posts\/1100\/revisions"}],"predecessor-version":[{"id":14059,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/posts\/1100\/revisions\/14059"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/media\/7466"}],"wp:attachment":[{"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/media?parent=1100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/categories?post=1100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/tags?post=1100"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/railsware.com\/blog\/wp-json\/wp\/v2\/coauthors?post=1100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}