User Tools

Site Tools


linux:mailconfigwithpostfix

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
linux:mailconfigwithpostfix [2014/05/22 13:31] – [test receiving mail] adminlinux:mailconfigwithpostfix [2022/10/29 16:15] (current) – external edit 127.0.0.1
Line 1: Line 1:
 +refer: http://tecadmin.net/install-and-configure-postfix-on-centos-redhat/
 +email architecture: [[linux:services#email_system_in_linux|email system in linux]]\\
 +http://www.postfix.org/documentation.html\\
 +http://postfix.state-of-mind.de/patrick.koetter/smtpauth/sasldb_configuration.html\\
 +{{:linux:postfix.ppt|postfix slide show}}
 +====== Mailserver config ======
 +===== install and config postfix for sending and receiving mail =====
 +==== install ====
 +  * install <code bash>
 +yum remove sendmail
 +yum install cyrus-sasl.x86_64 
 +yum install postfix
 +</code>
 +  * set MTA default to postfix<code base>
 +  alternatives --set mta /usr/sbin/postfix
 +  </code>
 +==== config and files ====
 +  * config files<code>
 +/etc/sasl2/smtpd.conf
 +/etc/postfix/main.cf
 +</code>
 +  * log<code>
 +/var/log/maillog
 +</code>
 +  * check content of config<code bash>
 +postconf
 +</code>
 +  * check configs which change by user(none default)<code bash>
 +postconf -n
 +</code>
 +==== Basic config ====
 +Basic config for Sending and receiving mail with UNIX system accounts
 +=== What domain name to use in outbound mail ===
 +Edit /etc/postfix/main.cf:
 +<code bash>
 +myhostname = mail.babies.vn
 +mydomain = babies.vn
 +myorigin = $mydomain
 +inet_interfaces = all
 +</code>
 +The **myorigin** parameter specifies the domain that appears in mail that is posted on this machine. Follow this configuration, send mail as "user@$mydomain"
  
 +To **secure the mailserver was can't be used by other server**, you can config inet_interfaces to localhost:<code bash>
 +inet_interfaces = localhost
 +</code>
 +=== what domains this machine will deliver locally ===
 +The **mydestination** parameter specifies what domains this machine will deliver locally, instead of forwarding to another machine.
 +
 +Edit /etc/postfix/main.cf:
 +<code bash>
 +mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
 +</code>
 +==== Active config in postfix ====
 +<code bash>
 +serivce postfix restart 
 +chkconfig postfix on
 +</code>
 +==== test sending and receiving mail ====
 +=== setup sendmail program: mailx ===
 +<code bash>
 +yum install mailx
 +yum install sendmail
 +</code>
 +=== test sending mail ===
 +<code bash>
 +mail [email protected]
 +Subject: Test
 +This is a email test
 +#Ctr+D
 +</code>
 +=== test receiving mail ===
 +Using gmail [email protected] send to [email protected] and [email protected]
 +  * Check receiving mail base on maillog: /var/log/maillog
 +    * log for mailto [email protected]: status=sent (delivered to mailbox)<code>
 +May 22 05:39:52 mail postfix/smtpd[4228]: connect from mail-qg0-f43.google.com[209.85.192.43]
 +May 22 05:39:52 mail postfix/smtpd[4228]: C968340900: client=mail-qg0-f43.google.com[209.85.192.43]
 +May 22 05:39:53 mail postfix/cleanup[4232]: C968340900: message-id=<CADwQOAhT-WZ2wBRmXx0eDsJvTK5FtqauqryDDPgDCA7PYed3tw@mail.gmail.com>
 +May 22 05:39:53 mail postfix/qmgr[4141]: C968340900: from=<[email protected]>, size=2268, nrcpt=1 (queue active)
 +May 22 05:39:53 mail postfix/local[4233]: C968340900: to=<[email protected]>, relay=local, delay=0.74, delays=0.71/0.02/0/0.01, dsn=2.0.0, status=sent (delivered to mailbox)
 +May 22 05:39:53 mail postfix/qmgr[4141]: C968340900: removed
 +May 22 05:39:53 mail postfix/smtpd[4228]: disconnect from mail-qg0-f43.google.com[209.85.192.43]
 +    </code>
 +    * log for mailto [email protected]: <[email protected]>: Recipient address rejected: User unknown in local recipient table<code>
 +May 22 05:43:13 mail postfix/anvil[4230]: statistics: max connection rate 1/60s for (smtp:209.85.192.43) at May 22 05:39:52
 +May 22 05:43:13 mail postfix/anvil[4230]: statistics: max connection count 1 for (smtp:209.85.192.43) at May 22 05:39:52
 +May 22 05:43:13 mail postfix/anvil[4230]: statistics: max cache size 1 at May 22 05:39:52
 +May 22 05:43:58 mail postfix/smtpd[4247]: connect from mail-qc0-f179.google.com[209.85.216.179]
 +May 22 05:43:59 mail postfix/smtpd[4247]: NOQUEUE: reject: RCPT from mail-qc0-f179.google.com[209.85.216.179]: 550 5.1.1 <[email protected]>: Recipient address rejected: User unknown in local recipient table; from=<[email protected]> to=<[email protected]> proto=ESMTP helo=<mail-qc0-f179.google.com>
 +May 22 05:43:59 mail postfix/smtpd[4247]: disconnect from mail-qc0-f179.google.com[209.85.216.179]
 +</code>
 +  * check mail content received in "mail_spool_directory = /var/mail"<code bash>
 +cat /var/mail/root
 +</code>Or<code bash>
 +mail
 +</code>
 +==== config user [email protected] can send mail to [email protected], base on UNIX system account====
 +Default , we can send mail to [email protected]. But we can't send mail to [email protected]. Below are steps forward emails of [email protected] to sale UNIX system account(sale is UNIX system account)
 +=== config ===
 +[/etc/postfix/main.cf]
 +  virtual_alias_maps = hash:/etc/postfix/virtual
 +  
 +[/etc/postfix/virtual]
 +  [email protected] sale, [email protected], [email protected], [email protected]
 +=== Active changes in config ===
 +  - run scripts below:<code bash>
 +postmap /etc/postfix/virtual
 +#=> generate /etc/postfix/virtual.db
 +</code>
 +  - reload postfix: /etc/init.d/postfix reload
 +  - check config:<code bash>
 +postmap -q [email protected] hash:/etc/postfix/virtual
 +</code>
 +  - Using [email protected] send mail to [email protected]
 +==== Check Mail Server Storage(MSS) for Receiving Email which postfix support ====
 +<code bash>
 +postconf -a
 +cyrus
 +dovecot
 +</code>
 +===== Install and config Mail Server Storage with cyrus for Mail client connecting =====
 +<code>
 +               ------------------
 +Incoming Mail |--+     Postfix  <-----------| Outgoing Mail  |
 +                -|----------------                     |
 +                ||     LMTP      |                     |
 +                -|----------------                     |
 +                |+>    Cyrus    +----------------+     |
 +                |+>    Imapd    ||---->            |
 +                -|--------------|-                 |
 +                ||Authentication||    2|        1|     |
 +                |+<    SASL    <+|                 |
 +                ------------------     |Receiving|  |Sending|
 +                                                     |
 +                                       +--------------------+
 +                                           Mail Client    |
 +</code>                                       
 +==== Install cyrus ====
 +<code bash>
 +yum install cyrus-imapd.x86_64
 +</code>
 +==== config postfix connect with cyrus via lmtp(local mail transfer protocol) ====
 +=== config postfix ===
 +<code bash>
 +postconf -e "mailbox_transport = lmtp:unix:/var/lib/imap/socket/lmtp"
 +</code>
 +=== config cyrus ===
 +[/etc/cyrus.conf]\\
 +  lmtpunix      cmd="lmtpd" listen="/var/lib/imap/socket/lmtp" prefork=1
 +=== active changes in config ===
 +<code bash>
 +/etc/init.d/postfix restart
 +/etc/init.d/cyrus-imapd restart
 +chkconfig postfix on
 +chkconfig cyrus-imapd on
 +</code>
 +==== Config Cyrus-Imapd for domain and mail client authentication ====
 +[/etc/imapd.conf]
 +<code>
 +admins: cyrus cyrusadm
 +</code>