RaspberryPi as a Mail Server


Home Forums Single board computers Raspberry Pi RaspberryPi as a Mail Server

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1820
    PMB
    Keymaster

    I’ve had a fetchmail-dovecot system running on a Ubuntu server for a couple of years without any problems. I thought I’d experiment a bit to see if I can set up a R-Pi to do the same thing, maybe storing the mail on a USB memory stick.

    This is just somewhere to make notes for my own use. It’s not intended to be a step-by-step how-to. If I was to get it working, I may expand it out.

    #1836
    PMB
    Keymaster

    Remember: this is just an apparently random series of notes that I’ll tidy up later.
    Reference only : Installed ubuntu server and specify a mail server
    .
    NOTE: I had this all formatted with code blocks etc. BUT the damned editor keeps deleting all the formatting
    (see here)
    so I’ve given up. I could drown the dick-head responsible for this “feature”.
    .
    $ sudo nano /etc/default/fetchmail
    . change START_DAEMON to yes to allow fetchmail to run LAMP and a few Misc Packages Linux Apache, MySQL, PHP.
    I probably installed things in the wrong order and it took a bit of sorting out.
    At various stages I got error messages that seemed to relate to dovecot.
    $ sudo apt-get install mc
    $ sudo apt-get install Apache2
    $ sudo apt-get install php5 libapache2-mod-php5
    $ sudo /etc/init.d/apache2 restart
    To test php
    $ sudo nano /var/www/testphp.php
    . <!–?php include(“config.php”);
    . mysql_connect(“$dbhost”, “$dbuname”, “$dbpass”);
    . mysql_select_db(“$dbname”);
    . echo mysql_error();
    . phpinfo();
    . ?–> http://192.168.1.56/testphp.php
    .
    $ sudo apt-get install mailutils
    $ sudo apt-get install mysql-server
    $ sudo nano /etc/mysql/my.cnf
    . bind-address = 127.0.0.1 #
    . change line to your IP address
    $ sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin
    $ sudo nano /etc/php5/apache2filter/php.ini extension=mysql.so # uncomment this line
    $ sudo /etc/init.d/apache2 restart
    Hostname What is the current hostname: hostname -f Change the hostname:
    $ sudo nano /etc/hostname pmb.co.nz
    $ sudo nano /etc/hosts
    . change hostname from original to new
    . change reverse DNS = determining a domain name from a given IP address
    …… install dnsutils = various client programs related to DNS:
    Then you can check the reverse DNS:
    $ dig -x “ip-address”
    .
    Install fetchmail
    Fetchmail is a remote mail retrieval and forwarding utility. It gets the mail in from one or a number of sources and puts it in a folder where it can be picked up by the next step in the process.
    $ sudo apt-get install fetchmail
    Edit the config file fetchmailrc in directory /etc
    $ sudo nano /etc/fetchmailrc
    $ sudo nano /etc/default/fetchmail
    . change START_DAEMON to yes ; to allow fetchmail to run
    $ sudo /etc/init.d/fetchmail start ; Starting fetchmail – gave an error: pi@pmb ~ $
    $ sudo /etc/init.d/fetchmail restart [….] Restarting mail retriever agent: fetchmailfetchmail: cannot open /var/log/fetchmail.log: Permission denied fetchmail: fetchmail: Cannot detach into background. Aborting.
    After trying various locations, I put the log file in -var-log-. Created a new user (paul) in the process. The error was fixed changing the log file ownership to fetchmail-root
    .
    Postfix
    A mail transport agent. A popular alternative to sendmail.
    $ sudo apt-get install postfix ; when prompted, select “internet with smarthost” and enter your mail name (pmb.co.nz): Redirect mail from root user to your user name then reload:
    $ sudo nano /etc/aliases root: paul sudo newaliases
    Edit the main postfix config file and change 3 lines at the end of the file and restart postfix:
    $ sudo nano /etc/postfix/main.cf
    . myorigin = $pmb.co.nz
    . mydestination = $pmb.co.nz, localhost.$pmb.co.nz, localhost
    . mynetworks = 127.0.0.0/8
    $ sudo /etc/init.d/postfix restart
    To test it, send email using php interactive shell (address, subject, body):
    . php -a mail (‘paul@pmb.co.nz’, “PMB- A simple test email”, “testing… testing…”);
    . extit ();
    .
    Dovecot
    Dovecot is a Mail Delivery Agent (MDA), set up as a IMAP or POP3 server. Mail is stored in /home/paul/Maildir/
    Edit these files to configure dovecot:
    $ sudo apt-get install dovecot-imapd dovecot-pop3d
    $ sudo nano /etc/dovecot/dovecot.conf
    $ sudo nano /etc/dovecot/10-auth.conf
    $ sudo nano /etc/dovecot/10-mail.conf
    $ sudo nano /etc/dovecot/10-pop3.conf
    . Create the Maildir for future users:
    $ sudo maildirmake.dovecot /etc/skel/Maildir
    $ sudo maildirmake.dovecot /etc/skel/Maildir/.Drafts
    $ sudo maildirmake.dovecot /etc/skel/Maildir/.Sent
    $ sudo maildirmake.dovecot /etc/skel/Maildir/.Trash
    $ sudo maildirmake.dovecot /etc/skel/Maildir/.Templates
    .
    For existing users:
    $ sudo cp -r /etc/skel/Maildir /home/paul/
    $ sudo chown -R paul:paul /home/paul/Maildir
    $ sudo chmod -R 700 /home/paul/Maildir
    .
    To start/stop/restart dovecot
    $ sudo /etc/init.d/dovecot start
    To see if dovecot is running: ps -A | grep dovecot
    .
    Mount the USB drive:
    The usb drive must be ext4 formatted so you can chown and chmod it.
    $ umount /dev/sda1
    $ sudo mkfs.ext4 /dev/sda1
    .
    Auto-mount USB drive at boot by adding to /etc/rc.local mount /dev/sda1 /home/paul/usb1_data
    .
    From /home/paul/ create a symlink to make the Maildir on the usb flash drive appear to be in /home/paul
    $ sudo ln -s /home/paul/usb1_data/Maildir Maildir
    .
    A useful command to determine the total size of a directory and everything in and below it:
    $ du -sh /directory/
    .
    NOTES:
    $ dpkg -S which sendmail
    $ sudo netstat -pel | grep smtp
    $ dpkg -S “$(sudo ps ux | grep 3281 | awk ‘{print $NF}’)” ; note 3281 came from the previous command result
    $ tail -f /var/log/mail.log ; view mail logs
    $ sudo fuser -uv 25/tcp ; show all processes listening on port 25
    .
    References: https://help.ubuntu.com/community/Dovecot
    .
    ERROR LOGS – REPAIRS NEEDED
    linaro@mail2:~$ tail -f /var/log/mail.log
    Jul 8 14:20:06 mail2 postfix/local[1065]: 69A3BFEA8: to=, orig_to=, relay=local, delay=38220, delays=38216/2.8/0/0.38, dsn=4.3.0, status=deferred (temporary failure)
    Jul 8 14:20:07 mail2 dovecot: lda(root): Error: user root: Initialization failed: Initializing mail storage from mail_location setting failed: mkdir(/root/Maildir) failed: Permission denied (euid=65534(nobody) egid=65534(nogroup) missing +w perm: /root, dir owned by 0:0 mode=0755)
    Jul 8 14:20:07 mail2 dovecot: lda(root): Error: user root: Initialization failed: Initializing mail storage from mail_location setting failed: mkdir(/root/Maildir) failed: Permission denied (euid=65534(nobody) egid=65534(nogroup) missing +w perm: /root, dir owned by 0:0 mode=0755)
    Jul 8 14:20:07 mail2 dovecot: lda(root): Fatal: Invalid user settings. Refer to server log for more information.
    Jul 8 14:20:07 mail2 postfix/local[1013]: 6B33BFE86: to=, orig_to=
    , relay=local, delay=91701, delays=91697/3.2/0/0.3, dsn=4.3.0, status=deferred (temporary failure)
    Jul 8 14:20:07 mail2 dovecot: lda(root): Fatal: Invalid user settings. Refer to server log for more information.
    Jul 8 14:20:07 mail2 postfix/local[923]: 89CDBFE91: to=, orig_to=
    , relay=local, delay=91520, delays=91517/3.2/0/0.3, dsn=4.3.0, status=deferred (temporary failure)
    Jul 8 14:20:07 mail2 dovecot: lda(root): Error: user root: Initialization failed: Initializing mail storage from mail_location setting failed: mkdir(/root/Maildir) failed: Permission denied (euid=65534(nobody) egid=65534(nogroup) missing +w perm: /root, dir owned by 0:0 mode=0755)
    Jul 8 14:20:07 mail2 dovecot: lda(root): Fatal: Invalid user settings. Refer to server log for more information.
    Jul 8 14:20:07 mail2 postfix/local[975]: 817AFFE89: to=, orig_to=
    , relay=local, delay=91606, delays=91602/3.5/0/0.14, dsn=4.3.0, status=deferred (temporary failure)
    q^C

    #1837
    PMB
    Keymaster

    reserved 1

    #1838
    PMB
    Keymaster

    reserved 2

    #2216
    PMB
    Keymaster

    Here’s a good one…

    Last night I noticed that our traffic was high by about 1G/day and had been for the last 3 days. Some investigating narrowed it to the email server. The logs showed postfix was rejecting a message as too large. A customer had sent a set of pictures totaling about 14MB. It’s been downloading 10MB and failing every 8 minutes for 3 days.

    I edited postfix main.cf to include “message_size_limit = 20480000”. All fixed.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.