你好,游客 登录 注册 搜索
背景:
阅读新闻

速搭建一个基于Web的Mail服务器实现邮件的收发

[日期:2013-04-18] 来源:Linux社区  作者:yhwhzhang [字体:大 中 小]
四、安装并调试postfix
1、安装postfix软件
  1. # groupadd -g 2525 postfix
  2. # useradd -g postfix -u 2525 -s /sbin/nologin -M postfix
  3. # groupadd -g 2526 postdrop
  4. # useradd -g postdrop -u 2526 -s /sbin/nologin -M postdrop
  5. # tar xf postfix-2.9.6.tar.gz
  6. # cd postfix-2.9.6
注:编译安装之前要注意系统时间是否一致;
  1. #hwclock -s #将虚拟机时间和硬件时间同步
  2. # make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl -DUSE_TLS ' 'AUXLIBS=-L/usr/lib/mysql -lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2 -lssl -lcrypto'
  3. # make
  4. # make install
按照以下的提示输入相关的路径([]号中的是缺省值,”]”后的是输入值,省略的表示采用默认值)
  1. install_root: [/] /
  2.  tempdir: [/root/postfix-2.9.3] /tmp/postfix
  3.  config_directory: [/etc/postfix] /etc/postfix
  4.  daemon_directory: [/usr/libexec/postfix]
  5.  command_directory: [/usr/sbin]
  6.  queue_directory: [/var/spool/postfix]
  7.  sendmail_path: [/usr/sbin/sendmail]
  8.  newaliases_path: [/usr/bin/newaliases]
  9.  mailq_path: [/usr/bin/mailq]
  10.  mail_owner: [postfix]
  11.  setgid_group: [postdrop]
  12. html_directory: [no]/var/www/html/postfix
  13. manpages: [/usr/local/man]
  14. readme_directory: [no]
2、调试并配置postfix软件,测试使用情况
  1. # vim /etc/init.d/postfix #添加服务启动脚本
  2. #!/bin/bash
  3. #
  4. # postfix Postfix Mail Transfer Agent
  5. #
  6. # chkconfig: 2345 80 30
  7. # description: Postfix is a Mail Transport Agent, which is the program \
  8. # that moves mail from one machine to another.
  9. # processname: master
  10. # pidfile: /var/spool/postfix/pid/master.pid
  11. # config: /etc/postfix/main.cf
  12. # config: /etc/postfix/master.cf
  13. # Source function library.
  14. . /etc/rc.d/init.d/functions
  15. # Source networking configuration.
  16. . /etc/sysconfig/network
  17. # Check that networking is up.
  18. [ $NETWORKING = "no" ] && exit 3
  19. [ -x /usr/sbin/postfix ] || exit 4
  20. [ -d /etc/postfix ] || exit 5
  21. [ -d /var/spool/postfix ] || exit 6
  22. RETVAL=0
  23. prog="postfix"
  24. start() {
  25. # Start daemons.
  26. echo -n $"Starting postfix: "
  27. /usr/bin/newaliases >/dev/null 2>&1
  28. /usr/sbin/postfix start 2>/dev/null 1>&2 && success || failure $"$prog start"
  29. RETVAL=$?
  30. [ $RETVAL -eq 0 ] && touch /var/lock/subsys/postfix
  31. echo
  32. return $RETVAL
  33. }
  34. stop() {
  35. # Stop daemons.
  36. echo -n $"Shutting down postfix: "
  37. /usr/sbin/postfix stop 2>/dev/null 1>&2 && success || failure $"$prog stop"
  38. RETVAL=$?
  39. [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/postfix
  40. echo
  41. return $RETVAL
  42. }
  43. reload() {
  44. echo -n $"Reloading postfix: "
  45. /usr/sbin/postfix reload 2>/dev/null 1>&2 && success || failure $"$prog reload"
  46. RETVAL=$?
  47. echo
  48. return $RETVAL
  49. }
  50. abort() {
  51. /usr/sbin/postfix abort 2>/dev/null 1>&2 && success || failure $"$prog abort"
  52. return $?
  53. }
  54. flush() {
  55. /usr/sbin/postfix flush 2>/dev/null 1>&2 && success || failure $"$prog flush"
  56. return $?
  57. }
  58. check() {
  59. /usr/sbin/postfix check 2>/dev/null 1>&2 && success || failure $"$prog check"
  60. return $?
  61. }
  62. restart() {
  63. stop
  64. start
  65. }
  66. # See how we were called.
  67. case "$1"in
  68. start)
  69. start
  70. ;;
  71. stop)
  72. stop
  73. ;;
  74. restart)
  75. stop
  76. start
  77. ;;
  78. reload)
  79. reload
  80. ;;
  81. abort)
  82. abort
  83. ;;
  84. flush)
  85. flush
  86. ;;
  87. check)
  88. check
  89. ;;
  90. status)
  91. status master
  92. ;;
  93. condrestart)
  94. [ -f /var/lock/subsys/postfix ] && restart || :
  95. ;;
  96. *)
  97. echo $"Usage: $0 {start|stop|restart|reload|abort|flush|check|status|condrestart}"
  98. exit 1
  99. esac
  100. exit $?
  101. # END
 
  1. # chmod +x /etc/init.d/postfix #添加执行权限
  2. # chkconfig --add postfix #添加服务启动级别
  3. # chkconfig --add postfix #将postfix服务添加至服务列表:
  4. # chkconfig postfix on #设置其开机自动启动:
  5. # service postfix restart #使用此脚本重新启动服务,以测试其能否正常执行:
  6. # newaliases #生成别名二进制文件:
3、配置postfix文件
  1. # cd /etc/postfix/
  2. # vim main.cf
 
  1. 修改以下几项为您需要的配置
  2. myhostname = mail.wangej.com #指定允许postfix的主机名,默认为本机名
  3. myorigin = wangej.com #指定发件人所在的域,做地址伪装
  4. mydomain = wangej.com #指定自身所在的域
  5. mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain, ns.$mydomain
  6. mynetworks = 172.16.0.0/16, 127.0.0.0/8#指定所在网络,postfix以此来判断是本地用户或远程
  7. # postconf -n #查看配置选项

注:
1、在postfix的配置文件中,参数行和注释行是不能处在同一行中的;
2、任何一个参数的值都不需要加引号,否则,引号将会被当作参数值的一部分来使用;
3、每修改参数及其值后执行 postfix reload 即可令其生效;但若修改了inet_interfaces,则需重新启动postfix;
4、如果一个参数的值有多个,可以将它们放在不同的行中,只需要在其后的每个行前多置一个空格即可;postfix会把第一个字符为空格或tab的文本行视为上一行的延续;

此时可以使用本地用户发送邮件,测试一下。

linux
相关资讯       Mail服务器 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款