Posts tagged mail
Stdout or a Pipe and a Tee
Mar 9th
If you have a binary that is outputting information to standard output, you can save the information 2 ways. You can direct the output to a file using >> or you can use a pipe with a tee. When you use >> you will not see the output, it will directly get dumped into the file, which is why the pipe and the tee is useful. Lets say you want to monitor your your mail.log. Open it with tail -f, and watch it on the screen:
sudo tail -f /var/log/mail.log
I find it interesting sometimes to watch spam and viruses get processed by the server.
Now if you want to save this output to a file other than the default mail.log you can direct the stdout to a file using >>:
sudo tail -f /var/log/mail.log >> ~/mail_bak.log
If you want to view the tail, while you are also saving it to a backup log file, use:
sudo tail -f /var/log/mail.log | tee ~/mail_bak.log
Two options, I use them both on occasion.
Sendmail – Critical to Receive System Alerts
Feb 10th

- Image via Wikipedia
The core of Linux is designed to mail, at minimum, the root user of various system alerts. With sendmail installed these alerts are mailed to the respective user directory. If you have an external mail server you can configure your local user mail to be forwarded to any email address. The easiest method is to place a .forward file in the users home directory. First create the file:
touch .forward
Then edit it:
nano .forward
Then add your email address to the file. All mails set to that particular user will now be forwarded to the added email address. People will say that you need to add the forwards directly to the aliases file in /etc/mail, but this is not necessary. It does work, and can be argued to be more “neat”, but .forward works just as well. Place a .forward file in each users directory. I use this on severs that I remotely manage. All system messages arre automatically forwarded to my incoming email server. There is no configuration needed for sendmail to work in this fashion. Just install it and system messages go to users, and then get forwarded as prescribed by .forward. Its secure against incoming messages unless port 25 has been forwarded to the local ip of the machine, from the router. And by default sendmail does not relay mail from external sources. Technically is will only send mail from the localhost, and even if there are other machines in your domain they cannot use sendmail without enabling a relay for them in the access file (/etc/mail/access).
Sendmail – Crontab and Email Updates
Feb 8th
Cron automatically sends out email to the job’s runner a report of the issued cronjob. This can either be an excellent and invaluable feature or an annoyance. To stop the emails from coming add this to the end of any particular cronjob:
>/dev/null 2>&1
Without the above line the email will be delivered to the mailbox. You can send the mail anywhere. I prefer setting up aliases in /etc/mail/aliases. This associated a particular user with possibly the email address of another domain. You can also put a MAILTO directive directly at the top of a particular users crontab:
MAILTO=" "
Note that sendmail will send outbound mail without any configurations necessary. Just install it:
sudo apt-get install sendmail
Test sendmail with:
mail -v user@domain.com
Write a subject, press enter, add something meaningless to the body, press control-d, then press enter on CC. Accepting mail is another story. To accecpt mail you need to open port 25, and make sure the external ip address is routing it to the local ip machine running sendmail. Then you have to configure sendmail to listen and accecpt email coming from this port. Then you need another application to retreive the mail from the users inbox. I prefer Dovecot. For more information on Dovecot please refer to:
KDE – Kmail
Dec 10th

I like kmail. It is the default mail client for KDE desktops. I have used Thunderbird for a long time now, but kmail is equivalent. So is evolution, which I use as well. Ultimately they all do the same thing; they are mail clients. Each one has comparable features, although they all look slightly different. I tend to use Thunderbird, but have grown an affinity for kmail. In particular, when Using Gnome I use Thunderbird, and when using KDE I use kmail.
Server Side Spam Filter – Sendmail – Dovecot – Procmail
Dec 6th
I tried for a long time to get sieve to work with sendmail. I could not get it to work. I would try and create a custom .m4 mailer, as per the sieve pages on the dovecot website, but nothing would work. Ultimately I gave up and used client side mail filtering built into Thunderbird. But this has a big drawback. A desktop session has to be logged on to keep the graphical application running. Because of this large amounts of system resources are consumed and end up being swapped out. As I would sit down at night it would take a significant amount of time for the desktop session to become responsive as it is retreived from swap. I tried disabling swap, but this was a no no because of MythTV’s commercial flagging. It would cause problems and lead to random system instability. Even with 8 gigs of ram my virtual server would sometimes crash. I don’t want this. Now I keep swap enabled and figured out how to get procmail to do server side mail filtering.
It was easy. Simply go into your sendmail.mc file and change the mailer. The default mailers are likely:
MAILER(local)
or
MAILER(smtp)
Install procmail and change the mailer accordingly:
MAILER(procmail)
Now go into your users home directory and touch a new file:
touch .procmailrc
Open it:
nano .procmailrc
Add:
GNU nano 2.0.7 File: .procmailrc
:0:
* ^X-Spam-Flag: YES
$HOME/mail/Junk
With this particular rule all messages flagged as spam, as per spamassassin, will be deposited into the Junk folder in the mail directory. It works as expected. For more information about sendmail, and how to configure spamassassin and clamav, visit a previous post.
Dovecot – Sieve, I Can’t Get Filtering to Work
Dec 1st
Maybe someone will help me. A rare thing to ask, but I cannot get sieve to work on my server. The plugin page, on the dovecot website, appears rather simple.
http://wiki.dovecot.org/LDA/Sieve
Install dovecot, then activate the sieve plugin. Here is what happens. I setup sendmail to use dovecot’s deliver and mail is no longer being accecpted from external ip address. The instructions say to create a dovecot.m4 file as reference it as a mailer in sendmail.mc. The file contains:
######################*****##############
### DOVECOT Mailer specification ###
##################*****##################
Mdovecot, P=/usr/local/libexec/dovecot/deliver, F=DFMPhnu9,
S=EnvFromSMTP/HdrFromSMTP, R=EnvToSMTP/HdrFromSMTP,
T=DNS/RFC822/X-Unix,
A=deliver -d $u
And the reference is indeed in sendmail.mc. While using smtp, and local as mailers email is received from external addresses. When using the dovecot mailer only local messages are processed. Also the local messages are not processed by sieve. I place .dovecot.sieve in my users home directory, but it does not work. I have read that it needs to be compiled into .dovecot.sievec, but I cannot find a sievec binary in my Debian OS. I’m thinking this has to do with permission issues. Maybe if I setup a new mail server, and have dovecot use mailboxes within the root partition, directly from /var/mail/%u then dovecot will have read/write permissions to the mail folders. Maybe this will allow sieve to compile the filters. Time permitting I will try this.
The setup instructions seem so simple:
protocol lda {
# Support for dynamically loadable plugins. mail_plugins is a space separated
# list of plugins to load.
mail_plugins = cmusieve # … other plugins like quota
}
Above simply shows how to load the cmusieve plugin in the lda protocol. This makes sense because the lda protocol will be used when the dovecot.m4 file is called by sendmail. But ultimately I have no server side mail filtering. Currently I use Thunderbird, client side, to filter my mail. Sometimes there is a delay and a message marked as spam, by the server side spamassassin, makes its way to my cell phone.
I really want server side mail filtering so I can logoff the desktop environment when I am not at home. But because Thunderbird must be running, to provide me functional filtering services, I cannot logoff. I really want to work this out. Any input from a reader will be appreciated.
![Reblog this post [with Zemanta]](http://img.zemanta.com/reblog_e.png?x-id=26acb3ec-f2eb-4726-b844-b0efc1e7727b)