email_advanced
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
email_advanced [2022/05/05 22:18] – [Introduction, and what you //will not// find here] fixed the fact that headline can't support other format peteyboy | email_advanced [2024/09/04 05:37] (current) – “// hc9 | ||
---|---|---|---|
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. | ||
+ | |||
+ | ===== Introduction ===== | ||
+ | |||
+ | ** and what you //will not// find here** | ||
+ | |||
+ | Here we discuss advanced topics for e-mail processing on SDF, mainly automatic processing of incoming messages with '' | ||
+ | |||
+ | ===== Forwarding E-Mail ===== | ||
+ | |||
+ | The '' | ||
+ | |||
+ | ^ line ^ description ^ | ||
+ | | '' | ||
+ | | '' | ||
+ | |||
+ | However, if you want to do more than forwarding to one address, use of '' | ||
+ | |||
+ | **Note:** On the SDF cluster hosts, your .forward should contain the following: | ||
+ | |||
+ | '' | ||
+ | |||
+ | Replace ‘username’ with your username. On the MetaArray, a .forward is not needed - the mail server on ma enables procmail processing for all users with a .procmailrc in their home directory. | ||
+ | |||
+ | ===== Fetching E-Mail ===== | ||
+ | |||
+ | Use '' | ||
+ | |||
+ | ==== Sample " | ||
+ | |||
+ | <file config .fetchmailrc> | ||
+ | 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 “procmail” (see “man procmail” for more information) allows to filter incoming mail following user defined rules; in particular, you can generate a [[# | ||
+ | |||
+ | ==== 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 '' | ||
+ | |||
+ | <file bash .procmailrc> | ||
+ | # 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 '' | ||
+ | |||
+ | If you want to use the mail directories proposed by nospam, you may prepend the above noted fragment by | ||
+ | |||
+ | '' | ||
+ | |||
+ | which will result in storing the “possibly bad” messages in '' | ||
+ | |||
+ | A sample '' | ||
+ | |||
+ | <file config .whitelist> | ||
+ | my.friend@his.domain.com | ||
+ | president@whitehouse.gov | ||
+ | myself@gmail.com | ||
+ | </ | ||
+ | |||
+ | All messages not coming from these three addresses would end up in the “quarantine” folder defined 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 '' | ||
+ | |||
+ | <file config SENDERIP> | ||
+ | SENDERIP = `formail -c -XReceived | grep "by mx.sdf.org" | ||
+ | grep -v "from mx.sdf.org" | ||
+ | sed " | ||
+ | </ | ||
+ | |||
+ | Then we'll begin the actual Procmail recipe, which will only be executed after checking to make sure that the “SENDERIP” variable exists and is in the correct format. Anything written to the “LOG” variable will be inserted into the log file. (New lines must be explicitly stated.) | ||
+ | |||
+ | < | ||
+ | EOL= " | ||
+ | " | ||
+ | :0 | ||
+ | * SENDERIP ?? ^^[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*^^ | ||
+ | { | ||
+ | LOG = "The sender' | ||
+ | </ | ||
+ | |||
+ | 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.$EOL" | ||
+ | |||
+ | :0: | ||
+ | Spam | ||
+ | } | ||
+ | |||
+ | LOG = "This sender is not a known source of spam.$EOL" | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | This completes the Procmail recipe. | ||
+ | |||
+ | ===== Not Having Your Mail Look Like Spam ===== | ||
+ | |||
+ | If you are using SDF's VPM service for your VHOST or other domain email accounts hosted here, you will want to add an SPF record so other services don't consider *your* email as spam: [[add_spf_record_for_your_vpm_mail|How to Add an SPF Record For Your VPM Mail]] | ||
+ | |||
+ | ===== Use SDF SMTP Server Remotely via SSH ===== | ||
+ | |||
+ | ==== Introduction: | ||
+ | |||
+ | Using SSH's port-forwarding capabilities, | ||
+ | |||
+ | **Prerequisites: | ||
+ | * SDF 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. | ||
+ | |||
+ | **example: | ||
+ | Use port //443// on SDF host “// | ||
+ | % ssh -4 -fN -p 443 -L 2525:mx:25 sdf_user@otaku.sdf.org | ||
+ | |||
+ | Note if public key authentication isn't setup a password prompt occurs. | ||
+ | |||
+ | ==== Tunnel Test: ==== | ||
+ | |||
+ | // | ||
+ | |||
+ | > % **telnet localhost 2525** | ||
+ | > Trying 127.0.0.1... | ||
+ | > | ||
+ | >Escape character is ' | ||
+ | >220 sdf.org ESMTP Sendmail 8.14.5/ | ||
+ | > | ||
+ | >221 2.0.0 sdf.org closing connection | ||
+ | > | ||
+ | |||
+ | ==== Tunnel Usage: ==== | ||
+ | |||
+ | Configure MUA to use “// | ||
+ | |||
+ | **example: | ||
+ | Configure and test the //Heirloom Mailx// MUA for user “// | ||
+ | > # **// | ||
+ | > 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.org ESMTP Sendmail 8.14.5/ | ||
+ | > >>> | ||
+ | > 250 sdf.org Hello IDENT: | ||
+ | > >>> | ||
+ | >250 2.1.0 ... Sender ok | ||
+ | > >>> | ||
+ | >250 2.1.5 ... Recipient ok | ||
+ | > >>> | ||
+ | >354 Enter mail, end with " | ||
+ | > >>> | ||
+ | > 250 2.0.0 pBD8LM7d000515 Message accepted for delivery | ||
+ | > >>> | ||
+ | > 221 2.0.0 sdf.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 -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 // | ||
+ | |||
+ | <file 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:// | ||
+ | |||
+ | ---- | ||
+ | |||
+ | [[http:// | ||