Postfix 邮件服务器搭建
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论