Postfix 邮件服务器搭建

发布于 2023-09-06 14:09:20 字数 2184 浏览 29 评论 0

Postfix 邮件服务器搭建,邮件服务器最好绑定域名,不然会被屏蔽

安装

sudo apt-get install mailutils

Add your domain to the config files, so others can't abuse your mailsystem:

postconf -e "myorigin = example.com"

Add your hostname (computer name). (Use command "hostname" at the command-line to display your hostname if not sure.)

postconf -e "myhostname=server1.example.com"

Now add the domain names that your system will handle.

postconf -e "relay_domains = example.com, example2.com, example3.com"

重启:

sudo service postfix restart

配置 postfix

sudo dpkg-reconfigure postfix

测试发送:

telnet localhost 25

测试:

mail from:<you@youremail.com>
rcpt to:<user@example.com>
data
To: user@example.com
From: you@youremail.com
Subject: Hey my first email
This is my first email on debian postfix after installing configuring it.
It was easy.

代码测试:

#!/usr/bin/env python
# -*- encoding: utf-8 -*-

import smtplib
from email.message import Message

class Mail:
    def __init__(self, config):
        self.__config = config
        self.__sender = self.__config['user']

    def send(self, receiver, subject, content):

        message = Message()
        message['Subject'] = subject
        message['From'] = self.__sender
        message['To'] = receiver
        message.add_header('Content-Type', 'text/html;charset=utf-8')
        message.set_payload(content)

        try:
            smtp = smtplib.SMTP()
            smtp.set_debuglevel(1)
            smtp.connect(self.__config['host'])
            smtp.sendmail(self.__sender, receiver, message.as_string())
            smtp.close()
            return True
        except Exception, error:
            print str(error)
            return False

if __name__ == '__main__':

    config = {
        'host': 'lives.ws',
        'user': 'no-reply@lives.ws',
    }

    mailer = Mail(config)
    mailer.send('twn39@163.com', 'python', 'python postfix test')
    print 'mail is send.'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

关于作者

文章
评论
26 人气
更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文