C
Published on
· Last modified on
· Public

使用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/

检查 IP 信用度:
http://anti-spam.org.cn/
http://www.justspam.org/check-an-ip

G
Published on

已星

C
Published on
greyby:

已星

谢谢

S
Published on

前来支持面条君,已星,求星。

B
Published on

已星,求星

C
Published on
simodorg:

前来支持面条君,已星,求星。

已星

C
Published on
batouy:

已星,求星

已星

M
Published on

已星,求星

C
Published on
mazyi:

已星,求星

已星

P
Published on

已星,求星

H
Published on

已星

H
Published on

已星,求星

I
Published on

已星 求星

Sign in or Sign up Leave Comment