DEV Community

MT
MT

Posted on • Originally published at chi.miantiao.me on

Setting up a Mail Sending Server with Haraka

Installation

npm install -g Haraka
Enter fullscreen mode Exit fullscreen mode

Initialization

haraka -i /etc/haraka
Enter fullscreen mode Exit fullscreen mode

DKIM Configuration

cd /etc/haraka/dkim
sh dkim_key_gen.sh miantiao.me
Enter fullscreen mode Exit fullscreen mode

DNS Configuration

  1. SPF Related:

Add a TXT record.

If it's a top-level domain, leave the hostname empty or use @. If it's a subdomain, use mail as the hostname (modify according to your subdomain). Value: v=spf1 ip4:49.74.15.209 ip4:192.168.199.219 ~all

Test if SPF is deployed successfully: http://www.openspf.org/Why?show-form=1

  1. DKIM Related:

Add a TXT record.

If it's a top-level domain, use mail._domainkey as the hostname. If it's a subdomain, use mail._domainkey.mail (change the second domain to your subdomain).

Value:

v=DKIM1;p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoWeQnE0B4ALbs9ih9UuG8xTo0pWo8u25487bNF8gqxbl6Ca+LNFvgHc6ADdObUfIEp1LD6C/6Ufq+mVab2pUjYAKQOxxNj20nHzRsHbElwkUaGD2gus5d+HcRYHRCQXh1bGuWXvhh9v4Bk1A6I8mWIl0SnN+sm0VUAOxwWUmlEWHVt7EmxaqxmgstzIdINwgxLW0TU+C+CgUEYe75BN42JsbYvfB2pYKMh9SS57aPDXgghUKX+SdMJL3ztbhfUujr3VhWg+cqyCIj3Yku9LKzxRRtnpaYJ1alv510Z1exUzcWRjXXJQMnND3a/9wkXpHi8wIYNfj4WqAyzf74MrhRQIDAQAB”
Enter fullscreen mode Exit fullscreen mode

Adding Users

cd /etc/haraka
echo 'auth/flat_file' >> plugins
vim auth_flat_file.ini
# Change methods to:
# methods=LOGIN
Enter fullscreen mode Exit fullscreen mode

In the file above, the left side in the [users] section is the account and the right side is the password (you can customize it):

[users]
matt=test
Enter fullscreen mode Exit fullscreen mode

Starting Haraka

haraka -c /etc/haraka
Enter fullscreen mode Exit fullscreen mode

Testing

# -*- coding: UTF-8 -*-
import smtplib  
from email.mime.text import MIMEText  

mailto_list=['test@qq.com'] # Recipient address
mail_host="127.0.0.1" # Server
mail_user="matt" # Username
mail_pass="test" # Password 
mail_postfix="miantiao.me" # Sender's domain

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],"Test Email Subject","""This is a test email"""):
            print "Sent successfully"
        else:
            print "Failed to send"
Enter fullscreen mode Exit fullscreen mode

Email server health test:

http://www.mail-tester.com/

Check IP reputation:

http://anti-spam.org.cn/

http://www.justspam.org/check-an-ip

stat

Top comments (0)