本文介绍使用Linux搭建SMTP服务器,通过搭配DNS记录修改达到SPF认证的目的。

本文参考:SMTP搭建教程

  1. 硬件要求
 CPU : 2C4T主存: >= 4GB硬盘规格 : >= 10GB操作系统 : Linux kernel >= 3.1x
  1. Postfix安装和配置
 apt -y install postfix sasl2-bin

  1. 选择Internet Site 选项的意思是使用SMTP收发送邮件

  2. 写上你的hostname

  3. 等待读条

  4. copy默认配置

 cp /usr/share/postfix/main.cf.dist /etc/postfix/main.cf
  1. 修改默认配置/etc/postfix/main.cf,uncomment为取消注释,comment为注释

    #line 78: uncomment
    mail_owner = postfix
    # line 94: uncomment and specify hostname
    myhostname = yourdomain.com
    # line 102: uncomment and specify domainname
    mydomain = yourdomain.com
    # line 123: uncomment
    myorigin = $mydomain
    # line 137: uncomment
    inet_interfaces = all
    # line 185: uncomment
    mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
    # line 228: uncomment
    local_recipient_maps = unix:passwd.byname $alias_maps
    # line 270: uncomment
    mynetworks_style = subnet
    # line 287: add your local network
    mynetworks = 127.0.0.0/8
    # line 407: uncomment
    alias_maps = hash:/etc/aliases
    # line 418: uncomment
    alias_database = hash:/etc/aliases
    # line 440: uncomment
    home_mailbox = Maildir/
    # line 576: comment out and add
    #smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
    smtpd_banner = $myhostname ESMTP
    # line 650: add
    sendmail_path = /usr/sbin/postfix
    # line 655: add
    newaliases_path = /usr/bin/newaliases
    # line 660: add
    mailq_path = /usr/bin/mailq
    # line 666: add
    setgid_group = postdrop
    # line 670: comment out
    #html_directory =
    # line 674: comment out
    #manpage_directory =
    # line 679: comment out
    #sample_directory =
    # line 683: comment out
    #readme_directory =
    # add to the end: limit an email size 10M
    message_size_limit = 10485760
    # limit mailbox 1G
    mailbox_size_limit = 1073741824
    # SMTP-Auth setting
    smtpd_sasl_type = dovecot
    smtpd_sasl_path = private/auth
    smtpd_sasl_auth_enable = yes
    smtpd_sasl_security_options = noanonymous
    smtpd_sasl_local_domain = $myhostname
    smtpd_recipient_restrictions = permit_mynetworks, permit_auth_destination, permit_sasl_authenticated, reject
    
    1. 使配置生效,并重启服务
      newaliases&&systemctl restart postfix
    

    如果提示,请确认mailq路径是否正确
    newaliases: fatal: file /etc/postfix/main.cf: parameter setgid_group:
    unknown group name: /usr/bin/mailq

    1. 配置发件账户
    #安装发信组件
    root@test:~# apt -y install dovecot-core dovecot-pop3d dovecot-imapd
    #修改发信配置文件
    root@test:~# vi /etc/dovecot/dovecot.conf
    
    1. 修改项如下
       # line 30: uncommentlisten = *, ::root@test:~# vi /etc/dovecot/conf.d/10-auth.conf# line 10: uncomment and change ( allow plain text auth     )disable_plaintext_auth = no# line 100: addauth_mechanisms = plain login
    
    1. 修改/etc/dovecot/conf.d/10-mail.conf

    2. 修改/etc/dovecot/conf.d/10-master.conf

       root@test:~# vi /etc/dovecot/conf.d/10-mail.conf# line 30: change to Maildirmail_location = maildir:~/Maildirroot@test:~# vi /etc/dovecot/conf.d/10-master.conf# line 96-98: uncomment and add# Postfix smtp-authunix_listener /var/spool/postfix/private/auth {mode = 0666user = postfixgroup = postfix}
    
    1. 重启postfix服务
     systemctl restart dovecot
    
    1. 添加访问账户
    # install mail client
    root@test:~# apt -y install mailutils
    # set environment variables to use Maildir
    root@test:~# echo 'export MAIL=$HOME/Maildir/' >> /etc/profile.d/mail.sh
    # add an OS user [ubuntu]
    root@test:~# adduser mailuser
    
    1. 测试发件
        ubuntu@test:~$ mail ubuntu@localhost# input CcCc:# input subjectSubject: Test Mail#1# input messagesThis is the first mail.# to finish messages, push [Ctrl + D] key# see received emailsubuntu@test:~$ mail"/home/ubuntu/Maildir/": 1 message 1 new>N   1 ubuntu    13/450   Test Mail#1# input the number you'd like to see an email? 1Return-Path: <ubuntu@mail.yourdomain.com>X-Original-To: ubuntu@localhostDelivered-To: ubuntu@localhostReceived: by mail.yourdomain.com (Postfix, from userid 1000)id A4B812069F; Fri, 1 XXX XXXXXXXX +0900 (JST)To: <ubuntu@localhost>Subject: Test Mail#1X-Mailer: mail (GNU Mailutils 3.4)Message-Id: <20180511055419.A4B812069F@mail.yourdomain.com>Date: Fri, XXXXXXXXXXXXXXXXXXX (JST)From: ubuntu <ubuntu@mail.yourdomain.com>This is the first mail.# to quit, input [q]? qSaved 1 message in /home/test/mboxHeld 0 messages in /home/test/Maildir/
    
    1. 配置TLS协议
    #编辑main.cf文件
    root@test:~# vi /etc/postfix/main.cf
    # add to the end
    smtpd_use_tls = yes
    smtp_tls_mandatory_protocols = !SSLv2, !SSLv3
    smtpd_tls_mandatory_protocols = !SSLv2, !SSLv3
    #这里需要替换为实际路径
    smtpd_tls_cert_file = /etc/yourcertfile
    smtpd_tls_key_file = /etc/yourtlsketfile
    smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
    #编辑 master.cf
    root@test:~# vi /etc/postfix/master.cf
    # line 17-21: uncomment like follows
    submission inet n  -    y     -     -     smtpd-o syslog_name=postfix/submission
    #  -o smtpd_tls_security_level=encrypt-o smtpd_sasl_auth_enable=yes-o smtpd_tls_auth_only=yes# line 29-31: uncomment like follows
    smtps  inet  n   -    y     -     -     smtpd-o syslog_name=postfix/smtps-o smtpd_tls_wrappermode=yesroot@test:~# vi /etc/dovecot/conf.d/10-ssl.conf
    # line 6: change
    ssl = yes
    # line 12,13: uncomment and specify certificates
    ssl_cert = "your ssl cert path"
    ssl_key =  "your ssl key path"
    #重启邮件服务
    root@test:~# systemctl restart postfix dovecot
    
    1. 如何判断已经启动SMTP服务?
      1、查看25端口和465是否监听中,25端口用于服务器中继,465端口用于账户校验
      2、 使用sendmail可以尝试给QQ邮箱发信,对端发件人显示root@‘yourdomain’.com
    echo 'test mail' | mail -s "Subject" -t  yourmail@qq.com
    

    3、使用Python2 SMTP库判断SMTP服务器启动情况

 # 实例代码try:server = smtplib.SMTP_SSL(smtp_server, 465)#server.ehlo()#server.starttls()#server.ehlo()#server.set_debuglevel(1)  # 用于显示邮件发送的执行步骤server.login('yourusername', yourpassword)# print to_addrsserver.sendmail(from_addr, to_addrs, msg.as_string())server.quit()except Exception, e:print "Error: unable to send email"print traceback.format_exc()

DNS模板样例,登录云供应商的管理平台修改DNS模板

如果有不成功的地方欢迎留言说明

Linux-SMTP中继服务器搭建相关推荐

  1. 扫描发送显示检查服务器,扫描仪通过SMTP中继服务器发送通知邮件失败(示例代码)...

    现象描述: 前2天有客户给我打电话说有1个办公地点的扫描仪扫描的文件多的话,收件人是无法收到通知邮件的,扫描仪上未显示任何错误:如果扫描的数量比较少如几张的话收件人就可以正常收到扫描通知邮件(客户的环 ...

  2. Linux Java Web 服务器搭建之tomcat安装

    Linux Java Web 服务器搭建之tomcat安装 一 Tomcat 简介 Tomcat 服务器是一个免费的开放源代码的Web 应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是 ...

  3. Linux下FTP服务器搭建

    Linux下FTP服务器搭建 一.FTP介绍 二.环境介绍 三.FTP服务端搭建步骤 1.安装相关软件包 2.启动FTP并检查状态 3.检查服务端口运行状态 4.修改FTP配置文件 5.关闭selin ...

  4. 服务器里面发邮件,通过SMTP中继服务器发送邮件的问题

    昨天写了一篇 SMTP中继服务器部署的文章,有朋友问我本地多个应用使用了不同的邮件通知地址,但发邮件的时候只能使用SMTP中继服务器上配置的地址才能发送,如下图: 所有的业务应用都必须配置成上图中的地 ...

  5. linux 中 svn 服务器搭建 重启

    鉴于在搭建时,参考网上很多资料,网上资料在有用的同时,也坑了很多人 本文的目的,也就是想让后继之人在搭建svn服务器时不再犯错,不再被网上漫天的坑爹作品所坑害,故此总结 /******开始****** ...

  6. linux 中 svn 服务器搭建 重启

    鉴于在搭建时,参考网上很多资料,网上资料在有用的同时,也坑了很多人 本文的目的,也就是想让后继之人在搭建svn服务器时不再犯错,不再被网上漫天的坑爹作品所坑害,故此总结 /******开始****** ...

  7. git hook 自动部署 linux git本地服务器搭建 git root 目录 git 仓库 git root/ .git

    服务器自动部署项目之GitHooks神器 - CSDN博客 -- 每次都是将本地将代码push到远程仓库,然后再ssh到服务器上git pull,甚是麻烦.在项目开发中使用git的时候,push之后, ...

  8. 微软office365服务器ip,使用Office365账号配置SMTP中继服务器

    · 如何将企业中的多功能设备(打印机.扫描仪等 )或应用程序设置为使用 Office 365 发送电子邮件,微软给出了3种方法: SMTP 客户端提交 直接发送 SMTP 中继 下面我主要是针对第3种 ...

  9. 使用Office 365账号配置SMTP中继服务器

    如何将企业中的多功能设备(打印机.扫描仪等 )或应用程序设置为使用 Office 365 发送电子邮件,微软给出了3种方法: SMTP 客户端提交 直接发送 SMTP 中继 以上3种方式的介绍,大家可 ...

  10. svn服务器配置文件添加用户后需要重启吗,linux 中 svn 服务器搭建 重启

    鉴于在搭建时,参考网上很多资料,网上资料在有用的同时,也坑了很多人 本文的目的,也就是想让后继之人在搭建svn服务器时不再犯错,不再被网上漫天的坑爹作品所坑害,故此总结 /******开始****** ...

最新文章

  1. Linux 网卡驱动相关——03
  2. android的签名问题
  3. 60+ 安全厂商的选择,为何 TA 一直坚持做威胁情报供应商?
  4. micropython 蓝牙音箱_你愿意用ESPY-core做哪些有趣尝试?
  5. 好用的shell_Linux系统安全 | Linux中的Shell和Bash
  6. 玩互联‮的网‬核心秘诀‮什是‬么? ​‎
  7. GDB 调试命令讲解-转
  8. Vue.js 2.0版
  9. 基于CST电磁仿真软件的波导弯头设计
  10. CF676A Nicholas and Permutation 题解
  11. 全国书画艺术之乡-----通渭
  12. pycharm破解补丁激活
  13. 开源商城WSTMart升级thinkphp5.1框架实践
  14. JAVA文件下载,IE不提示下载,直接打开的解决方法
  15. shell 计算磁盘使用率
  16. Settings学习总结(一)
  17. 【元胞自动机】元胞自动机交通事故通行【含Matlab源码 1345期】
  18. 电商网站适合用什么服务器?
  19. qt designer加载自定义组件
  20. CentOS 7系统中查看网卡信息

热门文章

  1. 王者并发课-铂金3:一劳永逸-如何理解锁的多次可重入问题
  2. 并发王者课-铂金3:一劳永逸-如何理解锁的多次可重入问题
  3. mysql 触发器delimiter_Mysql中的delimiter详解
  4. vue对文件夹进行拖拽上传完整流程(文件夹中超出100个文件)
  5. 某休闲游戏春节活动数据复盘
  6. 贾跃亭旗下FF年亏5.2亿美元:恒大持股20.5% 退市危机解除
  7. 断言(C++大师Andrei Alexandrescu的文章)[卸载microsoft visual c++ debug library]
  8. Android Launhcer 左屏实现以及左屏作为默认显示屏幕实现方法
  9. 电脑桌面一点计算机就切换,如何使用多个电脑桌面来全面提高工作效率?添加多桌面的方法...
  10. 阴阳师界面部分练习01