Push your emails to iOS devices via dovecot mailserver and boxcar

Since Apple implemented its push framework in iOS I wanted to have my emails pushed to my iPhone. The easiest way to do this is to use the service boxcar. To get my mails pushed to my iPhone I added the boxcar provider „Email Account“. With activating this provider I’ve got a boxcar forwarding mail address. Every mail sent to this address will be pushed to my iPhone. Although boxcar says that they don’t scan, save or use those mails for anything else than parsing the needed information to generate the push message, I am too paranoid to blindly trust them. So I don’t want to send the complete mails to them but only the subject and the sender. This post shows how I managed this with my mail server which runs dovecot 2 with the sieve plugin and postfix.

Since there is much documentation out there on setting up dovecot and postfix I’ll skip this part an concentrate on getting sieve running and forwarding received emails to the boxcar address.

At first you have to activate the sieve plugin by editing the dovecot configuration file (i.e. /etc/dovecot/dovecot.conf). Find the protocols section and make the lda part look like follows:

protocol lda {
  # Address to use when sending rejection mails.
  postmaster_address = postmaster@YOUR-DOMAIN.COM

  # Hostname to use in various parts of sent mails, eg. in Message-Id.
  # Default is the system's real hostname.
  hostname = YOUR-DOMAIN.COM

  # Support for dynamically loadable plugins. mail_plugins is a space separated
  # list of plugins to load.
  mail_plugins = sieve
  mail_plugin_dir = /usr/lib/dovecot/modules/lda

  # Binary to use for sending mails.
  sendmail_path = /usr/lib/sendmail

  # UNIX socket path to master authentication server to find users.
  auth_socket_path = /var/run/dovecot/auth-master
}

In the same file scroll down and find the plugin section. If it doesn’t exists, create it. Then make it look like as follows:

plugin {
  sieve=/var/vmail/%d/%n/.dovecot.sieve	#points to the users sieve rules file
  sieve_dir=/var/vmail/%d/%n/sieve #points to the users sieve directory
}

Those directives may very depending on the used system which in my case is debian squeeze.

After saving the config file and reloading dovecot, the sieve plugin should be ready. Now create the needed sieve rules in your .dovecot.sieve file (i.e. /var/vmail/YOUR-DOMAIN/YOU/.dovecot.sieve):

# Load the needed sieve plugins
require ["environment", "fileinto","imap4flags","envelope","enotify", "variables", "regex","reject","vacation","relational"];

# Don't forward mails from a specific mail
if anyof (address :contains "From" "YOU@YOUR-DOMAIN.COM")
{
        stop;
}
# Don't forward spam mails but move them into the junk folder and mark them as read
elsif anyof (header :contains "Subject" "***SPAM***",
        header :is "X-Spam-Flag" "YES")
{
        fileinto "Junk";
        setflag "\\Seen";
        stop;
}
# Send a new email to your boxcar address
elsif anyof ( header :matches "Subject" "*")
{
        # Capture the subject in a variable
        set "subject" "${1}";

        if anyof (header :matches "From" "*")
        {
                # Capture sender in a variable
                set "from" "${1}";
                # Send the mail
                notify :message "${subject}: ${from}" "mailto:YOUR-BOXCAR-ALIAS@push.boxcar.io";
        }
}

That’s it! If you run into problems or if you have and suggestions feel free to leave a comment.

Privacy Preference Center

Notwendig

Wordpress und die Plugins GDPR, WPTouch und W3 Total Cache benötigen diese Cookies, um zu funktionieren.

wptouch_customizer_mode,w3tc_referrer,gdpr[consent_types],gdpr[allowed_cookies],wp-settings-1,wp-settings-time-1

Analytics

Einfaches Benutzungstracking. Opt-out: https://www.redbrick.de/datenschutz/

PIWIK_SESSID,_pk_id.1.c4b2,_pk_ses.1.c4b2