Linux上配置postfix发送邮件

Config postfix for SM to send mail in Linux

Postfix is an alternative to Sendmail program. It starts at IBM research.

It will describe how to config postfix for SM to send mail to HP smtp server.

Test Env:

$ uname -a Linux smcfrd64 2.6.18-128.el5 #1 SMP Wed Dec 17 11:42:39 EST 2008 i686 i686 i386 GNU/Linux

SM version: SM 9.21.032

Linux computer IP: 16.186.77.7

Postfix 2.3.3.

If you are not root, please use sudo to run the commands below.

1. Install Postfix

1) Download postfix 2.3.3 from ftp://ftp.porcupine.org/mirrors/postfix-release/official/postfix-2.3.3.tar.gz.

2) Untar it to a directory, such as /home/admin/postfix 2.3.3, enter this directory

3) Config the build

If you need to support TLS/SSl, run the command below:

make makefiles CCARGS='-DUSE_TLS -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -DDEF_DAEMON_DIR=\"/usr/lib/postfix\" -DDEF_MANPAGE_DIR=\"/usr/share/man\" -DDEF_HTML_DIR=\"/usr/share/doc/postfix-2.3.3/html\" -DDEF_README_DIR=\"/usr/share/doc/postfix-2.3.3/README\" -I/usr/include/openssl -I/usr/include/sasl' AUXLIBS='-L/usr/lib -lssl -lcrypto -lsasl2'

4) Save existing Sendmail binary

Rename sendmail, newaliases and mailq program to other names. These binary may be in /usr/sbin, /usr/bin or other places.

5) Create user and group for postfix

  • Create a user account "postfix" with a user id and group id that are not used by any other user account. Preferably, this is an account that no-one can log into. The account does not need an executable login shell, and needs no existing home directory. My password and group file entries look like this:

/etc/passwd: postfix:*:12345:12345:postfix:/no/where:/no/shell

/etc/group: postfix:*:12345:

  • Create a group "postdrop" with a group id that is not used by any other user account. Not even by the postfix user account. My group file entry looks like:

/etc/group: postdrop:*:54321:

6) Compile postfix

$make

7) Install postfix

$make install (interactive version, first time install) or $make update (non-interactive version, for upgrades)

Note: The interactive version ("make install") asks for pathnames for Postfix data and program files, and stores your preferences in the main.cf file. If you don't want Postfix to overwrite non-Postfix "sendmail", "mailq" and "newaliases" files, specify pathnames that end in ".postfix". For the install root, just use the recommended value (/).

When install is finished, the postfix configuration will be stored at /etc/postfix/, main programs, such as sendmail, postmap, postconf, will be located at /usr/sbin.

2. Configure postfix

1) /etc/postfix/main.cf

The configuration items are added below:

alias_maps = hash:/etc/postfix/aliases

command_directory = /usr/sbin

config_directory = /etc/postfix

daemon_directory = /usr/lib/postfix

debug_peer_level = 2

html_directory = /usr/share/doc/postfix-2.3.3/html

inet_interfaces = localhost

mail_owner = postfix

mailq_path = /usr/bin/mailq

manpage_directory = /usr/share/man

mydomain = localdomain.com

myhostname = smcfrd64.localdomain.com

mynetworks = 16.186.77.7/29

mynetworks_style = host

newaliases_path = /usr/bin/newaliases

queue_directory = /var/spool/postfix

readme_directory = /usr/share/doc/postfix-2.3.3/README

relayhost = smtp.XX.com:25

sample_directory = /etc/postfix

sendmail_path = /usr/sbin/sendmail

setgid_group = postdrop

smtp_cname_overrides_servername = no

smtp_sasl_auth_enable = yes

smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd

smtp_sasl_security_options = noanonymous

smtp_sasl_type = cyrus

smtpd_sasl_auth_enable = yes

smtpd_sasl_path = smtpd

unknown_local_recipient_reject_code = 550

The items in bold font are added or modified compared to the original main.cf. The value of mynetworks is depended on the IP address and the network mask. It is necessary in my local env. To use external smtp server, the relayhost and other items prefix with smtp are necessary. After configure, you can run "postconf -n" to view all your postfix configuration.

2) /etc/postfix/aliases

In main.cf, we config the alias_maps to hash:/etc/postfix/aliases, edit file hash:/etc/postfix/aliases.

If you want to send a mail to jay@XX.com, you need to add an item for "jay" in this file:

jay: jay@XX.com.

Also, need to add an user jay to the Linux OS. Otherwise, when sending mail, the log will report unknown user error.

After configuration, generate the lookup table by the command followed:

$postmap hash:/etc/postfix/aliases

This command will generate a aliases.db file.

3) /etc/postfix/sasl_passwd

In main.cf, we config the smtp_sasl_password_maps to hash:/etc/postfix/sasl_passwd. This is necessary for postfix to send mail to external smtp server. Create file /etc/postfix/sasl_passwd and add the line to it:

smtp.XX.com:25 jay@XX.com:password

After configuration, generate the lookup table by the command followed:

$postmap hash:/etc/postfix/sasl_passwd

This command will generate a sasl_passwd.db file. Till now, you can remove the file sasl_passwd.

3. Start postfix

Run the command to start or restart postfix:

$/usr/sbin/postfix start (or reload)

4. Test it

$echo "test van Brunöö, this is één mail"|mail -s "test éne mail" XXXXX@XX.com

You can view the log /var/log/maillog to check whether the mail is sent successfully.

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值