设为首页 收藏本站
查看: 795|回复: 0

[经验分享] Linux上配置postfix发送邮件

[复制链接]

尚未签到

发表于 2015-11-24 09:01:23 | 显示全部楼层 |阅读模式
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 assendmail, 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, therelayhost 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、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-142880-1-1.html 上篇帖子: 使用postfix架设SMTP只用来发邮件 下篇帖子: fb8+postfix+sasl问题,可以pop,但smtp错误
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表