Posts tagged Sendmail

Sendmail – Critical to Receive System Alerts

HiRes image of Roadrunner, world's first petaf...
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).

Reblog this post [with Zemanta]

Sendmail – Crontab and Email Updates

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:

http://www.bgevolution.com/blog/dovecot-ubuntu-server/

Server Side Spam Filter – Sendmail – Dovecot – Procmail

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

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.

Sendmail – Yes, You Can Send Your Own Email

I’ve gone over sendmail several times, but ultimately it comes down to a couple of factors. Unless you are setting up an enterprise level email server, and require some login settings, and potential relaying, sendmail is relatively simple. You start by installing it:

sudo apt-get install sendmail

Sendmail operates on port 25 because it is an SMTP server. It will receive email and place it in /var/mail, and depending on how you setup virtual users, possibly with a virtusertable, the mail will go into a subfolder. With a virtusertable you map incoming addresses to particular users on the system, and you can use a catch all email address.

Enable the virtusertable as per this previous post:

http://www.bgevolution.com/blog/debian-sendmail-virtusertable/

Here is more info about how to configure the virtusertable:

http://www.bgevolution.com/blog/sendmail-consolidate-multiple-domains/

Go ahead and add some security by binding sendmail locally. This will allow your local email client to send and receive email locally. For the local machine itself set 127.0.0.1. My email server is in a virtual machine, therefore the host accesses the server by a local ip address. I also have to set sendmail to listen on the local ip address of the virtual machine.

DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA-local')dnl
DAEMON_OPTIONS(`Port=smtp,Addr=192.168.1.150, Name=MTA-network')dnl

Now if you have a php mailer script in your website it will have access to sendmail for email distribution purposes. Also your thunderbird will be able to connect to send mail. Now, even if you enable port forward sendmail should not respond. Any mail distribution requests originating from your external ip address, even if its forwarded to the local ip of the server, should not be responded to. You would have to create a daemon options line to access mail from the the external ip address.

There are other interesting things to deal with in sendmail. This is how you would integrate spamassassin into sendmail directly on the server. You can also integrate ClamAV, which I should get around to blogging about it soon. There are some tricky things to integrate ClamAV, on the server level, in Debian; but ultimately it relatively straight forward as compared to spamassassin.