Blog

Convert HTML emails to plain text and trim for SMS text messages

I forward emails from clients to my phone via SMS, i.e. mynumber@txt.att.net. Initially I thought something was wrong on my carrier’s side as I was only sporadically receiving them on my phone. However, it turned out these were HTML emails and the SMS gateway will not deliver those. Also, the tendency to reply with very long quotes results in excess texts as the limit is 160 characters per text message. Here is how to fix those two problems using procmail.

Setup a forward that pipes to /usr/bin/procmail (or whatever the location on your server). Below is my .procmailrc with the filters that worked for me:

SHELL=/bin/bash
MAILDIR=$HOME/mail/
:0
* ^Content-Type: text/html;
{
                    file = "$HOME/mail/prc.out"
                    LOCKFILE = $file$LOCKEXT
                    :0 fbw
                    | cat > $file && /usr/bin/lynx -dump $file
                    LOCKFILE
                }
                :0 E fbw
                | /usr/local/bin/perl -0777 -pe 's/<[^>]*>//g'
:0fbw
| cut -c 1-160                        
:0
  ! yournumber@txt.att.net
}
:0c
* ^Content-Type: text/plain;
{
  :0fbw
  | tr -s '\011\012 ' ' ' | cut -c 1-160
  :0
  ! yournumber@txt.att.net
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Warning: fsockopen(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/svosolutions/public_html/blog/wp-content/plugins/sweetcaptcha-revolutionary-free-captcha-service/library/sweetcaptcha.php on line 81 Warning: fsockopen(): unable to connect to www.sweetcaptcha.com:80 (php_network_getaddresses: getaddrinfo failed: Name or service not known) in /home/svosolutions/public_html/blog/wp-content/plugins/sweetcaptcha-revolutionary-free-captcha-service/library/sweetcaptcha.php on line 81