Install and Configure Cyrus on CentOS
|How to setup and configure Cyrus to handle email on CentOS server. A server without ability to send email is somehow still useless. Almost any kind of website scripts, CMS, and even turnkey sites are having email feature allowing visitors, users and anyone to send message to site’s admin. So if you are planning to build a CentOS server to host your websites in, you have to also install Postfix and Cyrus besides the LAMP or LNMP stack itself. I’ve posted about how to setup and configure Postfix earlier, today in this post I will also show you how to get Cyrus up and running on your server.
First, what is Cyrus anyway and why you’ll need it? Cyrus is simply a good companion for Postfix. This software helps your server to organize all emails.
Prerequisite
- A working CentOS server. In this guide I am using CentOS 6.3 x32 (see my playground server)
- Windows users should download Putty while Mac and Linux users can simply use Terminal
- You’ll also need a basic skill to use Putty and to navigate through SSH. Read: Most common Unix commands used to SSH.
- Your server should already has necessary software to host a website. In this case are: Apache, PHP5, and MySQL and Postfix.
- About 15 minutes of your time and a cup of tea if you like.
How To Install Cyrus
Step 1 – Login to your server and follow my previous guide about Basic setup for CentOS before you build a live web server. You may and may not follow that tutorial but if you followed, it will give you some basic security tweak to your server.
Before you proceed to the next steps, it is better to explain that all commands in this tutorial are written without the “sudo” prefix. However if you disabled root login and you logged in using another username with root privilege, you can add the “sudo” prefix all by your self. Alternatively you can simply type su, hit Enter and type in your password twice to switch login as root.
You may also need to type this command to go to the root directory:
cd ~
Step 2 – Now issue following command to install Cyrus with sasl component:
yum install cyrus-sasl
As usual, you may also need to confirm by typing Y then hit Enter.
Step 3 – Then also use following command to install Cyrus with imapd component:
yum install cyrus-imapd
Again, confirm it by typing Y.
How to configure Cyrus
Step 1 – Firstly, you have to edit the “smtpd.conf” file, the file that defines the authentication for Postfix/SASL. You can just use vi but in this example I prefer to use Nano editor:
nano /etc/sasl2/smtpd.conf
You’ll see initial lines as below:
Step 2 – Now replace what you see there with following:
pwcheck_method: auxprop auxprop_plugin: sasldb mech_list: PLAIN LOGIN CRAM-MD5 DIGEST-MD5
Once done Save that configuration (hit Control+O) then exit (Control+X).
Step 3 – Next, you have to also edit the “imapd.conf” file. Again, I use Nano:
nano /etc/imapd.conf
You’ll see some defaults lines as below:
Step 4 – Now delete all current lines and use following. p.s: You can copy and paste these text to Notepad then edit domain.com and server name with your actual domain:
virtdomains: userid defaultdomain: domain.com servername: mail.domain.com configdirectory: /var/lib/imap partition-default: /var/spool/imap admins: cyrus sievedir: /var/lib/imap/sieve sendmail: /usr/sbin/sendmail.postfix hashimapspool: true allowanonymouslogin: no allowplaintext: yes sasl_pwcheck_method: auxprop sasl_mech_list: CRAM-MD5 DIGEST-MD5 PLAIN tls_cert_file: /etc/pki/cyrus-imapd/cyrus-imapd.pem tls_key_file: /etc/pki/cyrus-imapd/cyrus-imapd.pem tls_ca_file: /etc/pki/tls/certs/ca-bundle.crt autocreatequota: -1 createonpost: yes autocreateinboxfolders: spam autosubscribeinboxfolders: spam
Once done Save that configuration (hit Control+O) then exit (Control+X). In my Playground server it looks like this:
Step 5 – Well actually that’s it. You are now having Postfix and Cyrus installed. What’s next? You can simply use your contact form in your website (if you built it already) and test it to send email to your personal email (like @gmail.com, @live.com or @yahoo.com). Alternatively you can also install MailX, a free open source email client software for your server so you’ll be able to send email right via command line.
Issue this command syntax:
yum install mailx
Again, confirm it with Y.
Once done, try to send a test email.
How to use MailX to send email from your CentOS server:
Step 1 – Each time you want to send an email, you have to issue following syntax:
mail recipient@someserver.com
Of course you have to replace recipient@someserver.com with the actual email address you wish to send the mail to. In this example, for testing purpose only, I use free disposable email service from GetAirmail.com.
Step 2 – Once you typed above command syntax and hit Enter, it will ask you to enter the subject of your email. So go ahead type the subject and hit Enter.
Step 3 – Upon hitting Enter, it’s just a blank line where you can then type the whole message there.
Step 4 – Once finished typing all the message, simply hit Enter then type a period (a dot) then hit Enter once again. The period indicates the end of your message and once you hit Enter, mailx sends your email directly. It should look like this:
So here’s the email sent in my inbox:
And here’s the message
Done. Do not forget to bookmark this page, share it on Twitter, Facebook and Google+. Do not hesitate to ask me question related to this “how to install Cyrus” guide. You can get quicker update by following me on Twitter.
How can I change the sender from root to admin or any other name, except root? 😀
I love all your tutorials. You give me so much strength to become independent. Everything works well. But, I think here you have left to mention, what the settings should look like in the case that we want to create multiple emails.
Take my case as examples. I have 5 sites, all of my clients have asked to get their emails. So, I would like to know how I can create the other four. So far the examples you have provided seems to be oriented for one email/domain idea.
Thanks.
Btw, I see, you have also received email in the form of
root@mail.fikitips.com
is there any way to remove that mail and replace it with root?How can I create mailboxes for different users and domains?