`
zhouxi2010
  • 浏览: 51036 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

配置postfix

阅读更多

由于一般web开发都有发送邮件的功能,django中也集成了该功能,所以用起来还是比较方便的,但是在生产环境,一般来说都是自己配置邮件服务器,其实可以想象,如果用户在你的网站注册了,然后收到的确认邮件来源是***@gmail.com等,可能就会觉得不正规。所以这里记录怎么粗糙的配置一下的postfix,然后在django中怎么使用。

第一步:先安装postfix, 我用的是ubuntu,直接apt-get就可以了

第二步:编辑/etc/postfix/main.cf,如下:

smtpd_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 "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

myhostname = kier-laptop
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mydestination =mydomain.com, kier-laptop, localhost.localdomain, localhost, 
relayhost = 
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = loopback-only
default_transport = error
relay_transport = error

smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
broken_sasl_auth_clients = yes
 

第三步:配置postfix的smtp认证:

先安装必要的包:

apt-get install libsasl2 sasl2-bin libsasl2-modules

 修改/etc/default/saslauthd:

START=yes
PWDIR="/var/spool/postfix/var/run/saslauthd"
PARAMS="-m ${PWDIR} -r"
PIDFILE="${PWDIR}/saslauthd.pid"
MECHANISMS="pam"
OPTIONS="-c -m ${PWDIR}"

 然后运行:

mkdir -p /var/spool/postfix/var/run/saslauthd
echo 'pwcheck_method: saslauthd' >> /etc/postfix/sasl/smtpd.conf
echo 'mech_list: plain login' >> /etc/postfix/sasl/smtpd.conf
 

第四步:adduser postfix sasl,设置用户postfix的密码为123456,后面会用到

第五步:chown postfix:sasl -R /var/spool/postfix

重启postfix, saslauthd

好了,现在在python命令行里面应该可以发邮件了,下面开始配置django工程里的setting文件:

EAMIL_HOST = 'localhost'
DEFAULT_FROM_EMAIL = 'noreply@mydomain.com'
EMAIL_HOST_USER = 'postfix'
EMAIL_HOST_PASSWORD = '123456'
 重启apache,试试吧
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics