This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| tutorials:e-mail-advanced [2012/05/01 20:03] – Add $ID tag memnon | tutorials:e-mail-advanced [2014/03/01 18:15] (current) – Tunnel to `mail.sdf-eu.org' instead of just `mail' memnon | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== E-Mail, Advanced Topics ====== | ||
| + | |||
| + | This tutorial discusses advanced topics concerning e-mail on SDF: spam filtering, automatic processing, forwarding. It is probably only useful for ARPA members. | ||
| + | |||
| + | ==== Contents ==== | ||
| + | |||
| + | - [[# | ||
| + | - [[# | ||
| + | - [[#Fetching E-Mail]] | ||
| + | - [[#Fighting Spam]] | ||
| + | - [[#Personal White List Against Spam]] | ||
| + | - [[#Using Procmail With a DNSBL]] | ||
| + | - [[#Use SDF SMTP Server Remotely via SSH]] | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ===== Introduction, | ||
| + | |||
| + | Here we discuss advanced topics for e-mail processing on SDF, mainly automatic processing of incoming messages with " | ||
| + | |||
| + | ===== Forwarding E-Mail ===== | ||
| + | |||
| + | The " | ||
| + | |||
| + | **somebody@somewhere.com**: | ||
| + | **|filterprogram**: | ||
| + | |||
| + | However, if you want to do more than forwarding to one address, use of " | ||
| + | |||
| + | ===== Fetching E-Mail ===== | ||
| + | |||
| + | Use " | ||
| + | |||
| + | ==== Sample " | ||
| + | |||
| + | < | ||
| + | poll pop.provider.net | ||
| + | proto pop3 | ||
| + | user " | ||
| + | pass " | ||
| + | is " | ||
| + | mda "/ | ||
| + | ssl; | ||
| + | </ | ||
| + | |||
| + | ===== Fighting Spam ===== | ||
| + | |||
| + | To fight unwanted bulk e-mail (spam), there are several possibilities available on SDF: | ||
| + | |||
| + | - As a general remark, think before you publish or tell somebody your e-mail address! And try to make clear to people that you don't want your address on a visible list of 500 recipients from somebody' | ||
| + | - SDF also supports plus-addressing; | ||
| + | - The [[http:// | ||
| + | - The automatic mail processor " | ||
| + | |||
| + | ==== nospam ==== | ||
| + | |||
| + | " | ||
| + | |||
| + | ===== Personal White List Against Spam ===== | ||
| + | |||
| + | //White lists// contain e-mail addresses which are always to be accepted as good. It is easy to implement this with " | ||
| + | |||
| + | //Note:// For this to be working, the following //must// have been set up: | ||
| + | |||
| + | * a " | ||
| + | * a standard " | ||
| + | |||
| + | The easiest method to install these files is by launching " | ||
| + | |||
| + | < | ||
| + | # procmail spamfilter using whitelist (2006 Yargo Bonetti) | ||
| + | # :: use at your own risk and any way you want! :: | ||
| + | # whitelist: file containing one valid e-mail address per line | ||
| + | # (only generic xxx@yyy.zz form, without " | ||
| + | WHITELIST=$MAILDIR/ | ||
| + | # spamfilter | ||
| + | FROM=`formail -c -x ' | ||
| + | :0 hb: | ||
| + | * ! ? grep -i -F -e " | ||
| + | $MAILDIR/ | ||
| + | </ | ||
| + | |||
| + | This will compare the address in the From: field of incoming messages to the ones saved in the file $MAILDIR/ | ||
| + | |||
| + | If you want to use the mail directories proposed by nospam, you may prepend the above noted fragment by | ||
| + | |||
| + | MAILDIR=$HOME/ | ||
| + | |||
| + | which will result in storing the " | ||
| + | |||
| + | A sample .whitelist may look like this: | ||
| + | |||
| + | < | ||
| + | my.friend@his.domain.com | ||
| + | president@whitehouse.gov | ||
| + | myself@gmail.com | ||
| + | </ | ||
| + | |||
| + | All messages not coming from these three addresses would end up in the " | ||
| + | |||
| + | ===== Using Procmail With a DNSBL ===== | ||
| + | |||
| + | DNSBL stands for "DNS blacklist", | ||
| + | |||
| + | (Thank you [[http:// | ||
| + | |||
| + | First make sure that " | ||
| + | |||
| + | Next Procmail should extract the IP address from which the message was sent. This is done using " | ||
| + | |||
| + | < | ||
| + | SENDERIP = `formail -c -XReceived | grep "by sdf.lonestar.org" | ||
| + | grep -v "from sdf.lonestar.org" | ||
| + | sed " | ||
| + | </ | ||
| + | |||
| + | Then we'll begin the actual Procmail recipe, which will only be executed after checking to make sure that the " | ||
| + | |||
| + | < | ||
| + | :0 | ||
| + | * SENDERIP ?? ^^[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*^^ | ||
| + | { | ||
| + | LOG = "The sender' | ||
| + | LOG = $SENDERIP | ||
| + | LOG = " | ||
| + | " | ||
| + | </ | ||
| + | |||
| + | The next step is to reverse the IP address because Spamhaus wants it that way. Procmail will then use " | ||
| + | |||
| + | < | ||
| + | SENDER_REVERSED = `expr " | ||
| + | sed " | ||
| + | |||
| + | KNOWNOFFENDER = `host " | ||
| + | sed " | ||
| + | </ | ||
| + | |||
| + | If Spamhaus returns an IP address between 127.0.0.0 and 127.0.0.9, then we know that this particular email is of dubious origin. In that case we can put it in the folder " | ||
| + | |||
| + | < | ||
| + | :0 | ||
| + | * KNOWNOFFENDER ?? ^^127.0.0.[0-9]*^^ | ||
| + | { | ||
| + | LOG = "This sender is a known source of spam. | ||
| + | " | ||
| + | |||
| + | :0: | ||
| + | Spam | ||
| + | } | ||
| + | |||
| + | LOG = "This sender is not a known source of spam. | ||
| + | " | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | This completes the Procmail recipe. | ||
| + | |||
| + | ==== Use SDF SMTP Server Remotely via SSH ==== | ||
| + | |||
| + | === Introduction === | ||
| + | |||
| + | Using SSH's port-forwarding capabilities, | ||
| + | |||
| + | Prerequisites: | ||
| + | * SDF[-EU] MetaARPA membership | ||
| + | * SSH plus suitable MUA (email program) | ||
| + | * public key authentication (optional) | ||
| + | |||
| + | === Tunnel Construction === | ||
| + | |||
| + | Port-forwarding can occur on ports 53, 110, 143, 443, and 993 on most SDF hosts. | ||
| + | On **SDF-EU**, use [[http:// | ||
| + | |||
| + | ex: | ||
| + | Use port 465 on SDF-EU host " | ||
| + | |||
| + | % ssh -4 -fN -p 465 -L 2525: | ||
| + | |||
| + | Note if public key authentication isn't setup a password prompt occurs. | ||
| + | |||
| + | === Tunnel Test === | ||
| + | |||
| + | telnet(1) can be used; type " | ||
| + | |||
| + | % telnet localhost 2525 | ||
| + | Trying 127.0.0.1... | ||
| + | Connected to localhost. | ||
| + | Escape character is ' | ||
| + | 220 sdf-eu.org ESMTP Sendmail 8.14.4/ | ||
| + | ^] | ||
| + | telnet> quit | ||
| + | Connection closed | ||
| + | |||
| + | === Tunnel Usage === | ||
| + | |||
| + | Configure MUA to use " | ||
| + | |||
| + | ex: | ||
| + | Configure and test the Heirloom Mailx MUA for user " | ||
| + | to use " | ||
| + | |||
| + | # $HOME/ | ||
| + | set smtp=" | ||
| + | set from=" | ||
| + | set replyto=" | ||
| + | |||
| + | % hmail -v someone@sdf.org | ||
| + | Subject: tunneled SMTP test | ||
| + | test 123 | ||
| + | . | ||
| + | Resolving host localhost . . . done. | ||
| + | Connecting to 127.0.0.1: | ||
| + | 220 sdf-eu.org ESMTP Sendmail 8.14.4/ | ||
| + | >>> | ||
| + | 250 sdf-eu.org Hello odin [178.63.35.194], | ||
| + | >>> | ||
| + | 250 2.1.0 < | ||
| + | >>> | ||
| + | 250 2.1.5 < | ||
| + | >>> | ||
| + | 354 Enter mail, end with " | ||
| + | >>> | ||
| + | 250 2.0.0 q08KTMoc023275 Message accepted for delivery | ||
| + | >>> | ||
| + | 221 2.0.0 sdf-eu.org closing connection | ||
| + | |||
| + | === Tunnel Teardown === | ||
| + | |||
| + | The SSH tunnel can be torn down by identifying the appropriate PID (process ID) and sending it a kill signal, via the kill(1) command or similar tool. The following illustrates the teardown process using sockstat(1) to determine the PID on the NetBSD operating system: | ||
| + | |||
| + | % sockstat -np 2525 | ||
| + | USER | ||
| + | frog ssh | ||
| + | |||
| + | % kill -HUP 24362 | ||
| + | Killed by signal 1. | ||
| + | |||
| + | === Tunnel Maintenance === | ||
| + | |||
| + | Network connections can fail for various reasons; a keep-alive script can help: | ||
| + | (script contributed by SDF user nullogic - thanks!) | ||
| + | |||
| + | <code bash> | ||
| + | #!/bin/bash | ||
| + | # sdftun.sh: Keep alive script for local ssh tunnel from home to SDF SMTP | ||
| + | |||
| + | SSH_USER= | ||
| + | SSH_HOST=' | ||
| + | SSH_PORT=443 | ||
| + | SSH_ARGS=' | ||
| + | TAG_HOST=mx | ||
| + | TAG_PORT=25 | ||
| + | LIS_PORT=8080 | ||
| + | LOG_FILE=~/ | ||
| + | SLEEP=" | ||
| + | |||
| + | while [ 1 ]; do | ||
| + | SSH_PID=`ps aux | sed -n -e /sed/d -e /ssh\ \-N/p | wc -m` | ||
| + | if [ $SSH_PID -eq 0 ]; then | ||
| + | ssh $SSH_ARGS $LIS_PORT: | ||
| + | -p$SSH_PORT &>/ | ||
| + | DATE_TIME=`date ' | ||
| + | echo " | ||
| + | fi | ||
| + | sleep $SLEEP | ||
| + | done | ||
| + | </ | ||
| + | |||
| + | Writing the PID to a file at the time of tunnel creation can simplify the ID process. | ||
| + | |||
| + | === References === | ||
| + | |||
| + | * Setting up [[http:// | ||
| + | * OpenSSH FAQ: How do I use [[http:// | ||
| + | |||
| + | $Id: e-mail-advanced.html, | ||