Notes:
SMTP creates guidelines for servers so that they can break up and transmit mail messages. .
SMTP roughly works as follows: when sending out a mail message with your mail client, all the
different parts (sender, recipient, message body, ...) are put together in the form of text strings. These
strings are separated by code words that SMTP can interpret so it knows what the "To:" address is,
what the "Subject" is and what the "Message Body" contains. SMTP then looks at the "To:" addres(ses)
and breaks it up into the user part (before the @) and the domain part (after the @). With this
information,
SMTP knows to which outside SMTP server to connect to deliver the mail. The receiving
SMTP server in turn knows all the different parts and uses the simple commands to see if it knows the
user that is in the "To:" part. If the user is known it will deliver the mail into the correct endpoint. When
the user retrieves his/her mail with a mail client, that client, in turn, understands in which field to put
which text when you are displaying the mail on your screen.
In our factory analogy the
SMTP daemon is the workstation sitting between the outside of our factory
and the start and endpoint of our conveyor belt. The factory has many gates on which things can be
delivered or sent, but the SMTP workstation sits at gate 25.
here domain name
=sherpa.com
Hostname
= mail.sherpa.com
ip addr
=192.168.0.100
to test
#hostname -s | -d | -f
s = short
d = domain
f = fqdn
STEP 1configure dns:
1 configure /etc/named.conf
2 . configure zone files
3 Configure your /etc/resolve.conf to use your DNS server
########################################################
Aliases
1 One to many or list alises
edit /etc/aliases
eg, add
sales2: hari,ram,user1,jack,pack,mack
save/exit
#newaliases //this will update aliases.db aliease database file do ls -l | grep aliases to see changes
use mutt and send mail to sales2 or sales2@sherpa.com and see these defined user get the msg.
2. one to one
eg. postfix
: root
manager
: bossco
in total there are 5..
############################################################################
yum install dovecot
vi /etc/dovecot/dovecot.conf
line
21 protocols = imap pop3
33 login_greeting = this is selflearning lab.
vim /etc/dovecot/conf.d/10-auth.conf
11 disable_plaintext_auth = no
97 auth_mechanisms = plain login
vim /etc/dovecot/conf.d/10-mail.conf
24 mail_location = maildir:~/Maildir
vi /etc/dovecot/conf.d/10-master.conf
enable imap and pop 3 ports and
check following
75 service auth {
76 # auth_socket_path points to this userdb socket by default. It's typically
77 # used by dovecot-lda, doveadm, possibly imap process, etc. Its default
78 # permissions make it readable only by root, but you may need to relax these
79 # permissions. Users that have access to this socket are able to get a list
80 # of all usernames and get results of everyone's userdb lookups.
81 unix_listener auth-userdb {
82 mode = 0600
83 user = postfix
84 group = postfix
85 }
save exit
yum install dovecot
vi /etc/dovecot/dovecot.conf
line
21 protocols = imap pop3
33 login_greeting = this is selflearning lab.
vim /etc/dovecot/conf.d/10-auth.conf
11 disable_plaintext_auth = no
97 auth_mechanisms = plain login
vim /etc/dovecot/conf.d/10-mail.conf
24 mail_location = maildir:~/Maildir
vi /etc/dovecot/conf.d/10-master.conf
enable imap and pop 3 ports and
check following
75 service auth {
76 # auth_socket_path points to this userdb socket by default. It's typically
77 # used by dovecot-lda, doveadm, possibly imap process, etc. Its default
78 # permissions make it readable only by root, but you may need to relax these
79 # permissions. Users that have access to this socket are able to get a list
80 # of all usernames and get results of everyone's userdb lookups.
81 unix_listener auth-userdb {
82 mode = 0600
83 user = postfix
84 group = postfix
85 }
save exit
[root@mail conf.d]# telnet localhost 110
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK this is selflearning lab.
user ram
+OK
pass redhat
+OK Logged in.
list
+OK 4 messages:
1 522
2 517
3 569
4 2323
.
retr 4
...
quit
telnet localhost 143 for testing imap
For our TLS to work we need at least two files a KEY file and CERTIFICATE file these file should be in PEM format
to generate our own certificate and key
openssl req -new -x509 -days 3650 -nodes -out /etc/postfix/certs/cert.pem -keyout /etc/postfix/certs/key.pem
configure centos6.4 dvd yum repo
and
rpm -i http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-redhat93-9.3-1.noarch.rpm
and
yum install postgresql93-server postgresql93-contrib
[root@mail data]# pwd
/var/lib/pgsql/9.3/data
[root@mail data]# service postgresql-9.3 initdb
Initializing database: [ OK ]
[root@mail data]# chkconfig postgresql-9.3 on
[root@mail data]# service postgresql-9.3 start
------------------------------------------------------------------------
[root@mail conf.d]# telnet localhost 110
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK this is selflearning lab.
user ram
+OK
pass redhat
+OK Logged in.
list
+OK 4 messages:
1 522
2 517
3 569
4 2323
.
retr 4
...
quit
telnet localhost 143 for testing imap
install postgre from its repo
do #service postgresql-9.3 initdb && service postgrelql-9.3 start && service postgresql-9.3 on
open up /var/lib/pgsql/9.3/data/pg_hba.conf
80 local all all md5 ##change from peer to md5
at end add
host mail mailreader 127.0.0.1/32 md5
host mail mailreader ::1/128 md5
----------------
su postgres
basg 4.1$ psql <enter>
postgres#alter user postgres password 'abc123';
postgres#\q
service postgres-9.3 restart
psql -U postgres
create user mailreader with password 'nepal123';
revoke create on schema public from public
revoke usage on schema public from public
grant create on schema public from postgres;
grant usage on schema public from postgres;
create database mail with owner mailreader;
\c mail
note: The default style of configuring Postfix mailboxes is to use your Unix user accounts and map them to
mailboxes on your harddrive. Instead of using Unix accounts we will use Postfix's "Virtual Mailbox"
mechanism to tie email and destination on your harddrive together.
<contd switched inside mail database>
$ CREATE TABLE users (
email TEXT NOT NULL,
password TEXT NOT NULL,
realname TEXT,
maildir TEXT NOT NULL,
created TIMESTAMP WITH TIME ZONE DEFAULT now(),
PRIMARY KEY (email)
);
#groupadd -g 1000 email //adding group 'email' with id 1000
#useradd -g email -u 200 -d /home/mail -s /sbin/nologin mailreader
$ yum install postgresql93-contrib or check rpm -qa | grep postgre
connect to database 'mail'
create extension pgcrypto;
$ INSERT INTO users (
email,
password,
realname,
maildir
) VALUES (
'foo@yourdomain.com',
crypt('ecnrypted_password',gen_salt('bf',5)),
'Foo Lastname',
'foo/'
);
$ CREATE TABLE transports (
domain TEXT NOT NULL,
gid INTEGER UNIQUE NOT NULL,
transport TEXT NOT NULL,
PRIMARY KEY (domain)
);
$ INSERT INTO transports (
domain,
gid,
transport
) VALUES (
'exmaple.com',
1000,
'virtual:'
);
////////for aliases or virtual maps
$ CREATE TABLE aliases (
alias TEXT NOT NULL,
email TEXT NOT NULL,
PRIMARY KEY (alias)
)
And insert some data for demonstration purposes:
$ INSERT INTO aliases (
alias,
email
) VALUES (
'bar@exmaple.com',
'foo@example.com'
);
$ ALTER DATABASE mail OWNER TO mailreader;
Then alter the user for each table in your database:
$ ALTER TABLE users OWNER TO mailreader;
$ ALTER TABLE transports OWNER TO mailreader;
$ ALTER TABLE aliases OWNER TO mailreader;
better!
But Postfix and PostgreSQL still don't know of each others existence. PostgreSQL is just sitting there,
waiting to be read out, we have to instruct Postfix to get its information not from files but from the
database. This is done by creating mapping files for the different Postfix mechanisms. These files will
hold the queries which will return the necessary information to Postfix. For our setup to work we will
have to create 4 different mapping files for transport, uids, gids, mailboxes.
Lets start with our mailboxes. Postfix needs to know which mailboxes exist so that when it receives
mail on foo@example.com it knows that it can accept it. Instead of writing a database connect
statement and a real query, the mapping files are in a right side and left side syntax.
Open up a new file called mailboxes.cf and put in your database information:
$ user=mailreader
password=secret
dbname=mail
table=users
select_field=maildir
where_field=email
hosts=localhost
save this file in logical directory, the default is
"/etc/postfix/pgsql/mailboxes.cf"
Let continue with the remaining four files. Open up a new file with the name transport.cfand build
your query:
$ user=mailreader
password=secret
dbname=mail
table=transports
select_field=transport
where_field=domain
hosts=localhost
Our third file will be called virtual.cf:
$ user=mailreader
password=secret
dbname=mail
table=aliases
select_field=email
where_field=alias
hosts=localhost
Now that we have our files ready for Postfix, we still need to tell it to use these files to communicate
with PostgreSQL. For making this happen, open up the good old main.cffile from Postfix, go to the
bottom and start telling about PostgreSQL!
$ local_recipient_maps =
virtual_uid_maps = static:200
virtual_gid_maps = static:1000
transport_maps = pgsql:/etc/postfix/pgsql/transport.cf
virtual_mailbox_base = /home/mail
virtual_mailbox_maps = pgsql:/etc/postfix/pgsql/mailboxes.cf
virtual_maps = pgsql:/etc/postfix/pgsql/virtual.cf
mydestination = $mydomain, $myhostname
configure rpmfore for installation of amavis
yum install amavisd-new
yum install clamd
testing email
#telnet localhost 25
....
ehlo localhost
mail from: user01
....OK
rcpt to:user02
..OK
data
...
this is testing mail from user01
quit
#tail -f /var/log/maillog