{"id":1969,"date":"2014-10-02T14:38:09","date_gmt":"2014-10-02T21:38:09","guid":{"rendered":"http:\/\/www.wellgolly.com\/?p=1969"},"modified":"2016-05-25T14:22:17","modified_gmt":"2016-05-25T21:22:17","slug":"processing-email","status":"publish","type":"post","link":"https:\/\/www.wellgolly.com\/?p=1969","title":{"rendered":"Processing remove requests and bad email addresses in our customer list."},"content":{"rendered":"<p>Update 2016-05-25. I found a <a href=\"http:\/\/www.wellgolly.com\/?p=2490\">much easier way<\/a>.<\/p>\n<h2>Remove Requests<\/h2>\n<p>We don\u2019t like to bother our customers with lots of emails, but from time to time we let them know about new products and sales. Some of them use the remove link on the bottom of the email to unsubscribe from the list. I have a rule in Apple Mail that automatically routes the remove response to a folder. We usually get a couple of remove requests each time we send out a mailing and we usually process them manually. I wanted to automate the process a bit and create a master list of email addresses that do not want our mailings. That way if someone orders from us under a different name or address, we won\u2019t be sending them email if they opted out earlier.<\/p>\n<p>After looking around in the Library\/Mail folder it looks like our Remove folder is located at<br \/>\n<pre><code class=\"preserve-code-formatting\">\n ~\/Library\/Mail\/V2\/Mailboxes\/Remove.mbox\/\n<\/code><\/pre><\/p>\n<p>I CD to that folder and then redirect the results of a recursive grep command to a file on the desktop. Since they are responding to our email, I look for the <\/i>From:<\/i> portion of the email. Note the period after the search term. I means to look for all files in the current directory. The -r says to look in all files in directories below this one too.<br \/>\n<pre><code class=\"preserve-code-formatting\">\ngrep -r &quot;From: &quot; . &gt; ~\/Desktop\/Remove.txt\n<\/code><\/pre><\/p>\n<p>Then I open the file in BBEdit and remove extra lines, e.g. anything with our company name.<\/p>\n<p>I only want the email addresses, so I can use this grep line to remove everything before the address.<br \/>\n<pre><code class=\"preserve-code-formatting\">\n.*&lt;\n<\/code><\/pre><br \/>\nI can remove everything after the address with this.<br \/>\n<pre><code class=\"preserve-code-formatting\">\n&gt;.*\n<\/code><\/pre><br \/>\nSort the lines and process duplicates and you\u2019re done. I then import the email addresses into my MySQL database.<\/p>\n<h2>Bad Domain<\/h2>\n<p>Our mail server will try to find missing domains for a few days and generates warning messages. When it finally gives up it generates a message with the subject \u201cReturned mail: see transcript for details\u201d. The nice thing about these messages is that the failed address is easy to find. It looks like this:<br \/>\n<pre><code class=\"preserve-code-formatting\">\nThe following address(es) failed:\n\n abby612@earthink.net\n&nbsp;&nbsp; retry timeout exceeded\n<\/code><\/pre><\/p>\n<p>In this case it probably couldn\u2019t find the server because it was looking for earthink but the email was probably to earthlink. When I pull them out of the failure message, I correct obvious mis-typing before adding them to the bad email database.<br \/>\nThe code to find the addresses is:<br \/>\n<pre><code class=\"preserve-code-formatting\">\ngrep -r &quot;^ .*@.*$&quot; . &gt; ~\/Desktop\/Failed.txt\n<\/code><\/pre><br \/>\nThe code looks for lines starting with a space, then an email address, then the end of the line. There are surprisingly few false positives e.g. lines that contain other things than just an email address.<\/p>\n<h2>Bad Addresses<\/h2>\n<p>It\u2019s much harder to remove the bad email addresses since the format from different email providers varies tremendously. I ended up looking for lines that contain an \u201c@\u201d and doing a lot of manual cleanup. I\u2019ll see if I can figure out a better way next month.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Update 2016-05-25. I found a much easier way. Remove Requests We don\u2019t like to bother our customers with lots of emails, but from time to time we let them know about new products and sales. Some of them use the remove link on the bottom of the email to unsubscribe from the list. I have &hellip; <a href=\"https:\/\/www.wellgolly.com\/?p=1969\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Processing remove requests and bad email addresses in our customer list.<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-1969","post","type-post","status-publish","format-standard","hentry","category-coding"],"_links":{"self":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/1969","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1969"}],"version-history":[{"count":0,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/1969\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1969"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1969"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1969"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}