宝塔服务器面板,一键全能部署及管理,送你10850元礼包,点我领取

这期内容当中小编将会给大家带来有关ubuntu配置外部smpt将email 发送外网的操作过程,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

  1. 添加heirloom-mailx apt源
    cat /etc/apt/sources.list.d/mailx.list
    deb http://cz.archive.ubuntu.com/ubuntu xenial main universe

  2. 更新apt
    apt update

  3. 安装heirloom-mailx
    apt  install  heirloom-mailx  -y

  4. 配置外部发件邮箱
    编辑 /etc/s-nail.rc在最后加上:

    for 163邮箱

    set from="xxxxx@163.com"     #发件地址
    set smtp="smtps://smtp.163.com:465"     #smtp服务器
    set smtp-auth-user="xxxxxx@163.com"    #登录发件地址
    set smtp-auth-password="xxxx"      #明文密码
    set smtp-auth=login      #登录方式,默认是login,也可以改成CRAM-MD5或PLAIN方式

    for outlook

    set from="xxxx@outlook.com"
    set smtp="outlook.office365.com:587"
    set smtp-auth-user="xxxx@outlook.com"
    set smtp-auth-password="xxxx"        #明文密码
    set smtp-use-starttls    #加密方式
    set ssl-verify=ignore    # 忽略ssl认证
    set smtp-auth=login

    for QQ mail

    set from="xxx@qq.com"
    set smtp="smtps://smtp.qq.com:465"
    set smtp-auth-user="xxx@qq.com"
    set smtp-auth-password="ahkphxxabcbshabbga" #QQ邮箱授权码
    set smtp-auth=login

  5. 常用命令
    常用命令:
    n:不读入设置文件本系统中是/etc/s-nail.rc)(这个文件允许用户使用外部邮件传输代理而不是使用系统自带的sendmail发送邮件)。
    s:设置邮件的主题信息。
    c:使用一个抄送列表。
    b:使用一个密送列表。

  6. 发送测试邮件
    echo "内容"|s-nail -s "主题" xxxx@163.com,xxxx@outlook.com #多个邮箱用逗号隔开
    或者:
    s-nail  -s "邮件主题" xxx@163.com   < result.txt
    加参数v可以看到mail输出的详细信息
    s-nail  -vs "邮件主题" xxx@163.com  < result.txt

  7. 发送带附件
    s-nail -a 附件 -s "主题" 收件地址 < 文件邮件正文.txt)
    s-nail -a /xxx.tar.gz -s "主题" xxx@163.com < ./xxx.txt

  8. shell 当编辑器,编辑完内容后按Ctrl-D结束
    s-nail -s '主题‘ xxx@163.com