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

[经验分享] ubuntu安装postfix+esmtp验证配置

[复制链接]

尚未签到

发表于 2015-11-24 10:10:06 | 显示全部楼层 |阅读模式
  https://help.ubuntu.com/community/Postfix
  
http://onexin.iyunv.com/source/plugin/onexin_bigdata/https://help.ubuntu.com/htdocs/ubuntunew/img/cap-top.png
http://onexin.iyunv.com/source/plugin/onexin_bigdata/https://help.ubuntu.com/htdocs/ubuntunew/img/logo.pnghttp://onexin.iyunv.com/source/plugin/onexin_bigdata/https://help.ubuntu.com/htdocs/ubuntunew/img/help-faq.pngCommunity Documentation

  • Login to Edit
Ubuntu Documentation > Community Documentation > Postfix

  • Postfix
Introduction  目录

  • Introduction
  • What is a Mail Transfer Agent
  • Installation
  • Configuration
  • Authentication
  • Testing
  • Troubleshooting

    • Remove Postfix from chroot
    • Configuring saslauthd to Default

  • Using Port 587 for Secure Submission
  • Other Postfix Guides

    • Postfix Basic Setup
    • Postfix Virtual Mailbox and Antivirus Filtering
    • Postfix Setup For Sender Policy Framework (SPF) Checking
    • Postfix Setup For DKIM email signing and verification
    • Add Dspam to Postfix
    • Postfix Complete Solution
    • Dovecot LDAP
    • Dovecot SASL

  Postfix is the default Mail Transfer Agent (MTA) for Ubuntu.  It is in Ubuntu's main repository, which means that it receives security updates. This guide explains how to install and configure postfix and set it up as an SMTP server using a secure connection.
What is a Mail Transfer Agent  In other words, it's a mail server not a mail client like Thunderbird, Evolution, Outlook, Eudora, or a web-based email service like Yahoo, GMail, Hotmail, Earthlink, Comcast, SBCGlobal.net, ATT.net etc.... If you worked for a company named Acme and owned acme.com, you could provide your employees with email addresses @acme.com. Employees could send an receive email through your computer, but not without your computer running all the time.  If all your email addresses are at a domain (@gmail.com, @yahoo.com) you do not own (you don't own Google) or do not host (acme.com) then you do not need this at all.   
Installation  In order to install Postfix with SMTP-AUTH and TLS, first install the postfix package from the Main repository using your favorite package manager. For example:
sudo aptitude install postfix  Simply accept the defaults when the installation process asks questions. The configuration will be done in greater detail in the next stage.
Configuration  From a terminal prompt:
sudo dpkg-reconfigure postfix  Insert the following details when asked (replacing server1.example.com with your domain name if you have one):

  •   General type of mail configuration: Internet Site
  •   NONE doesn't appear to be requested in current config
  •   System mail name: server1.example.com
  •   Root and postmaster mail recipient: <admin_user_name>
  •   Other destinations for mail: server1.example.com, example.com, localhost.example.com, localhost
  •   Force synchronous updates on mail queue?: No
  •   Local networks: 127.0.0.0/8
  •   Yes doesn't appear to be requested in current config
  •   Mailbox size limit (bytes): 0
  •   Local address extension character: +
  •   Internet protocols to use: all
  Now is a good time to decide which mailbox format you want to use.  By default Postifx will use  mbox for the mailbox format.  Rather than editing the configuration file directly, you can use the postconf command to configure all postfix parameters.  The configuration parameters will be stored in /etc/postfix/main.cf file. Later if you wish to re-configure a particular parameter, you can either run the command or change it manually in the file.
  To configure the mailbox format for Maildir:
sudo postconf -e 'home_mailbox = Maildir/'  You may need to issue this as well:
sudo postconf -e 'mailbox_command ='  Note: This will place new mail in /home/username/Maildir so you will need to configure your Mail Delivery Agent to use the same path.
  Configure Postfix to do SMTP AUTH using SASL (saslauthd):
sudo postconf -e 'smtpd_sasl_local_domain ='sudo postconf -e 'smtpd_sasl_auth_enable = yes'sudo postconf -e 'smtpd_sasl_security_options = noanonymous'sudo postconf -e 'broken_sasl_auth_clients = yes'sudo postconf -e 'smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination'sudo postconf -e 'inet_interfaces = all'  Next edit /etc/postfix/sasl/smtpd.conf and add the following lines:
pwcheck_method: saslauthdmech_list: plain login  Generate certificates to be used for TLS encryption and/or certificate Authentication:
touch smtpd.keychmod 600 smtpd.keyopenssl genrsa 1024 > smtpd.keyopenssl req -new -key smtpd.key -x509 -days 3650 -out smtpd.crt # has promptsopenssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 3650 # has promptssudo mv smtpd.key /etc/ssl/private/sudo mv smtpd.crt /etc/ssl/certs/sudo mv cakey.pem /etc/ssl/private/sudo mv cacert.pem /etc/ssl/certs/  Configure Postfix to do TLS encryption for both incoming and outgoing mail:
sudo postconf -e 'smtp_tls_security_level = may'sudo postconf -e 'smtpd_tls_security_level = may'sudo postconf -e 'smtpd_tls_auth_only = no'sudo postconf -e 'smtp_tls_note_starttls_offer = yes'sudo postconf -e 'smtpd_tls_key_file = /etc/ssl/private/smtpd.key'sudo postconf -e 'smtpd_tls_cert_file = /etc/ssl/certs/smtpd.crt'sudo postconf -e 'smtpd_tls_CAfile = /etc/ssl/certs/cacert.pem'sudo postconf -e 'smtpd_tls_loglevel = 1'sudo postconf -e 'smtpd_tls_received_header = yes'sudo postconf -e 'smtpd_tls_session_cache_timeout = 3600s'sudo postconf -e 'tls_random_source = dev:/dev/urandom'sudo postconf -e 'myhostname = server1.example.com' # remember to change this to yours  The file /etc/postfix/main.cf should now look like this:
  
# See /usr/share/postfix/main.cf.dist for a commented, more complete versionsmtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)biff = no# appending .domain is the MUA's job.append_dot_mydomain = no# Uncomment the next line to generate &quot;delayed mail&quot; warnings#delay_warning_time = 4hmyhostname = server1.example.comalias_maps = hash:/etc/aliasesalias_database = hash:/etc/aliasesmyorigin = /etc/mailnamemydestination = server1.example.com, example.com, localhost.example.com, localhostrelayhost =mynetworks = 127.0.0.0/8mailbox_command = procmail -a &quot;$EXTENSION&quot;mailbox_size_limit = 0recipient_delimiter = +inet_interfaces = allsmtpd_sasl_local_domain =smtpd_sasl_auth_enable = yessmtpd_sasl_security_options = noanonymousbroken_sasl_auth_clients = yessmtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destinationsmtpd_tls_auth_only = no#Use these on Postfix 2.2.x only#smtp_use_tls = yes#smtpd_use_tls = yes#For Postfix 2.3 or above use:smtp_tls_security_level = maysmtpd_tls_security_level = maysmtp_tls_note_starttls_offer = yessmtpd_tls_key_file = /etc/ssl/private/smtpd.keysmtpd_tls_cert_file = /etc/ssl/certs/smtpd.crtsmtpd_tls_CAfile = /etc/ssl/certs/cacert.pemsmtpd_tls_loglevel = 1smtpd_tls_received_header = yessmtpd_tls_session_cache_timeout = 3600stls_random_source = dev:/dev/urandom  Restart the postfix daemon like this:
sudo /etc/init.d/postfix restartAuthentication  The next steps are to configure Postfix to use SASL for SMTP AUTH.
  First you will need to install the libsasl2-2,  sasl2-bin and libsasl2-modules from the Main repository [i.e. sudo apt-get install them all].
  Note: if you are using Ubuntu 6.06 (Dapper Drake) the package name is libsasl2.
  We have to change a few things to make it work properly. Because Postfix runs chrooted in /var/spool/postfix we have change a couple paths to live in the false root.  (ie. /var/run/saslauthd becomes /var/spool/postfix/var/run/saslauthd):
  
http://onexin.iyunv.com/source/plugin/onexin_bigdata/https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=warning.pngNote: by changing the saslauthd path other applications that use saslauthd may be affected.

  First we edit /etc/default/saslauthd in order to activate saslauthd. Remove # in front of START=yes, add the PWDIR, PARAMS, and PIDFILE lines and edit the OPTIONS line at the end:
  
# This needs to be uncommented before saslauthd will be run automaticallySTART=yesPWDIR=&quot;/var/spool/postfix/var/run/saslauthd&quot;PARAMS=&quot;-m ${PWDIR}&quot;PIDFILE=&quot;${PWDIR}/saslauthd.pid&quot;# You must specify the authentication mechanisms you wish to use.# This defaults to &quot;pam&quot; for PAM support, but may also include# &quot;shadow&quot; or &quot;sasldb&quot;, like this:# MECHANISMS=&quot;pam shadow&quot;MECHANISMS=&quot;pam&quot;# Other options (default: -c)# See the saslauthd man page for information about these options.## Example for postfix users: &quot;-c -m /var/spool/postfix/var/run/saslauthd&quot;# Note: See /usr/share/doc/sasl2-bin/README.Debian#OPTIONS=&quot;-c&quot;#make sure you set the options here otherwise it ignores params above and will not workOPTIONS=&quot;-c -m /var/spool/postfix/var/run/saslauthd&quot;  Note: If you prefer, you can use &quot;shadow&quot; instead of &quot;pam&quot;. This will use MD5 hashed password transfer and is perfectly secure. The username and password needed to authenticate will be those of the users on the system you are using on the server.
  Next, we update the dpkg &quot;state&quot; of /var/spool/postfix/var/run/saslauthd.  The saslauthd init script uses this setting to create the missing directory with the appropriate permissions and ownership:
  
dpkg-statoverride --force --update --add root sasl 755 /var/spool/postfix/var/run/saslauthd  This may report an error that &quot;--update given&quot; and the &quot;/var/spool/postfix/var/run/saslauthd&quot; directory does not exist. You can ignore this because when you start saslauthd next it will be created.
  Finally, start saslauthd:
  
sudo /etc/init.d/saslauthd startTesting  To see if SMTP-AUTH and TLS work properly now run the following command:
  telnet localhost 25
  After you have established the connection to your postfix mail server type
  ehlo localhost
  If you see the lines
250-STARTTLS250-AUTH  among others, everything is working.
  Type quit to return to the system's shell.
TroubleshootingRemove Postfix from chroot  If you run into issues while running Postfix you may be asked to remove Postfix from chroot to better diagnose the problem.  In order to do that you will need to edit /etc/postfix/master.cf locate the following line:
smtp      inet  n       -       -       -       -       smtpd  and modify it as follows:
  
smtp      inet  n       -       n       -       -       smtpd  Then restart Postfix:
  
sudo /etc/init.d/postfix restartConfiguring saslauthd to Default  If you don't want to run Postfix in a chroot, or you'd like to not use chroot for troubleshooting purposes you will probably also want to return saslauthd back to its default configuration.
  The first step in accomplishing this is to edit /etc/default/saslauthd comment the following lines we added above:
  
#PWDIR=&quot;/var/spool/postfix/var/run/saslauthd&quot;#PARAMS=&quot;-m ${PWDIR}&quot;#PIDFILE=&quot;${PWDIR}/saslauthd.pid&quot;  Then return the saslauthd dpkg &quot;state&quot; to its default location:
  
dpkg-statoverride --force --update --add root sasl 755 /var/run/saslauthd  And restart saslauthd:
  
sudo /etc/init.d/saslauthd restartUsing Port 587 for Secure Submission  If you want to use port 587 as the submission port for SMTP mail rather than 25 (many ISPs block port 25), you will need to edit /etc/postfix/master.cf and uncomment the line  
submission inet n      -       n       -       -       smtpdOther Postfix Guides  These guides will teach you how to setup Postfix mail servers, from basic to advanced.
Postfix Basic Setup  Postfix Basic Setup Howto will teach you the concepts of Posfix and how you can get Postfix basics set up and running. If you are new to Postfix it is recomended to follow this guide first.
Postfix Virtual Mailbox and Antivirus Filtering  Postfix Virtual MailBox ClamSmtp Howto will teach you how to setup virtual mailboxes using non-Linux accounts where each user will authenticate using their email address with Dovecot POP3/IMAP server and ClamSMTP Antivirus to filter both incoming and out going mails for known viruses.
Postfix Setup For Sender Policy Framework (SPF) Checking  Postfix SPF will show you how to add SPF checking to your existing Postfix setup. This allows your server to reject mail from unauthorized sources.
Postfix Setup For DKIM email signing and verification  Postfix DKIM will guide you through the setup process of dkim-milter for you existing Postfix installation. This will allow your server to sign and verify emails using DKIM.
Add Dspam to Postfix  Postfix Dspam will guide you through the setup process of dspam for you existing Postfix installation. This will enable on your mail server high quality statistical spam filter Dspam.
Postfix Complete Solution  Postfix Complete Virtual Mail System Howto will help you if you are managing a large number of virtual domains at an ISP level or in a large corporation where you mange few hundred or thousand mail domains. This guide is appropriate if you are looking a complete solution with:

  • Web based system administration
  • Unlimited number of domains
  • Virtual mail users without the need for shell accounts
  • Domain specific user names
  • Mailbox quotas
  • Web access to email accounts
  • Web based interface to change user passwords
  • IMAP and POP3 support
  • Auto responders
  • SMTP Authentication for secure relaying
  • SSL for transport layer security
  • Strong spam filtering
  • Anti-virus filtering
  • Log Analysis
Dovecot LDAP  The Postfix/DovecotLDAP guide will help you configure Postfix to use Dovecot as MDA with LDAP users.  
Dovecot SASL  The PostfixDovecotSASL guide will help you configure Postfix to use Dovecot's SASL implementation.  Using Dovecot SASL may be preferable if you want to run Postfix in a chroot and need to use Cyrus SASL for other services.
  Note: this guide has been tested on Ubuntu 6.06 (Dapper) and Ubuntu 7.10 (Gutsy)
  CategoryEmail
  Postfix  (2012-02-19 00:43:41由christian-blackburn编辑)

  • Page History
  The material on this wiki is available under a free license, see Copyright / License for details
You can contribute to this wiki, see Wiki Guide for details

  --------------------------------
  增加smtp验证用户时像加linux用户一样(使用的是shadow库来验证)
  然后记得使用passwd设置一下密码
  测试
  ------
  
smtp使用演示
运行 windows的cmd窗口
按以下步骤使用命令
smtp的信息
用户名:p
域名:r.chinahrd.net
提示:不能收信,只发
密码:kdjfkkdie*&^(^e.{][
密码base64后:a2RqZmtrZGDQ0MyM2amRqamUue11b
用户名base64后:cGdA==
VXNlcm5hbWU6经过base64解码后:Username:
UGFzc3dvcmQ6经过base64解码后:Password:
data中的内容请按标准输入,现只做是否成功演示,忽略收信后内容
auth login:smtp的登录命令
mail from:发件人命令
rcpt to:收件人命令
data:输入内容
.+回车:表示输入内容结束
quit退出smtp
ehlo chinahrd.net:出示身份
--------cmd中输入开始---------
telnet 219.22.28.530 25
ehlo chinahrd.net
auth login
czdA==
a2RqZmDQ0MyM2amRqamUue11b
mail from:post@r.chinahrd.net
rcpt to:qidizi@qq.com
data
subject:cWlkaXpp
kkkkk
.
quit
---cmd输入结束----

运维网声明 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-142973-1-1.html 上篇帖子: postfix 删除队列中的邮件 下篇帖子: ubuntu下postfix邮件服务器安装
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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