Total Pageviews

Saturday 22 July 2017

使用Haraka搭建邮件发送服务器

安装: npm install -g Haraka

初始化: haraka -i /etc/haraka
DKIM 配置:
cd /etc/haraka/dkim
sh dkim_key_gen.sh miantiao.me
DNS 配置:
  1. SPF 相关:
    添加 TXT 记录
    如果是顶级域名主机名为空或者@,如果是子域名,主机名是mail(根据你的子域名修改) 值:v=spf1 ip4:49.74.15.209 ip4:192.168.199.219 ~all 在线测试 SPF 是否部署成功:http://www.openspf.org/Why?show-form=1
  2. DKIM相关:
    添加 TXT 记录
    如果是顶级域名主机名为主机名为mail._domainkey,如果是子域名自己主机名为mail._domainkey.mail(第二个域名改为你的子域名)
    值:"v=DKIM1;p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoWeQnE0B4ALbs9ih9UuG8xTo0pWo8u25487bNF8gqxbl6Ca+LNFvgHc6ADdObUfIEp1LD6C/6Ufq+mVab2pUjYAKQOxxNj20nHzRsHbElwkUaGD2gus5d+HcRYHRCQXh1bGuWXvhh9v4Bk1A6I8mWIl0SnN+sm0VUAOxwWUmlEWHVt7EmxaqxmgstzIdINwgxLW0TU+C+CgUEYe75BN42JsbYvfB2pYKMh9SS57aPDXgghUKX+SdMJL3ztbhfUujr3VhWg+cqyCIj3Yku9LKzxRRtnpaYJ1alv510Z1exUzcWRjXXJQMnND3a/9wkXpHi8wIYNfj4WqAyzf74MrhRQIDAQAB"
添加用户:
cd /etc/haraka
echo 'auth/flat_file' >> plugins
vim auth_flat_file.ini
#修改为methods:
#methods=LOGIN
上面的文件中[users]组里边左边是帐号,右边是密码(可以自定义):
[users]
matt=test
启动 Haraka:
haraka -c /etc/haraka
测试:
# -*- coding: UTF-8 -*-
import smtplib  
from email.mime.text import MIMEText  

mailto_list=['xxx@qq.com'] #收件地址
mail_host="127.0.0.1"  #设置服务器
mail_user="matt"    #用户名
mail_pass="test"   #口令 
mail_postfix="miantiao.me"  #发件箱的后缀
  
def send_mail(to_list,sub,content):  
    me="Haraka"+"<"+mail_user+"@"+mail_postfix+">"  
    msg = MIMEText(content,_subtype='plain',_charset='utf-8')
    msg['Subject'] = sub  
    msg['From'] = me  
    msg['To'] = ";".join(to_list)  
    try:  
        server = smtplib.SMTP()  
        server.connect(mail_host)  
        server.login(mail_user,mail_pass)  
        server.sendmail(me, to_list, msg.as_string())  
        server.close()  
        return True  
    except Exception, e:  
        print str(e)  
        return False  
if __name__ == '__main__':
    for mail in mailto_list:
        if send_mail([mail],"测试邮件的标题","""这是测试邮件"""):
            print "发送成功"
        else:
            print "发送失败"
邮箱服务器健康度测试:
http://www.mail-tester.com/

No comments:

Post a Comment