背景: ubuntu中安装sendmail发送邮件;
1.环境配置
sudo apt install sendmail sudo apt install sendmail-cf
sudo apt-get install mailutils
2.检查是否安装成功:
ps aux | grep sendmail root 1403610 0.0 0.2 22908 4504 ? Ss 00:45 0:00 sendmail: MTA: accepting connections root 1405103 0.0 0.0 9032 740 pts/0 S+ 00:47 0:00 grep --color=auto sendmail
3.默认情况下,sendmail只会为本机发送邮件,如需发送到internet,需改动 /etc/mail/sendmail.mc:
sudo vim /etc/mail/sendmail.mc
修改smtp的127.0.0.1为0.0.0.0:
FEATURE(`no_default_msa')dnl dnl DAEMON_OPTIONS(`Family=inet6, Name=MTA-v6, Port=smtp, Addr=::1')dnl DAEMON_OPTIONS(`Family=inet, Name=MTA-v4, Port=smtp, Addr=127.0.0.1')dnl dnl DAEMON_OPTIONS(`Family=inet6, Name=MSP-v6, Port=submission, M=Ea, Addr=::1')dnl DAEMON_OPTIONS(`Family=inet, Name=MSP-v4, Port=submission, M=Ea, Addr=127.0.0.1')dnl
为:
FEATURE(`no_default_msa')dnl dnl DAEMON_OPTIONS(`Family=inet6, Name=MTA-v6, Port=smtp, Addr=::1')dnl DAEMON_OPTIONS(`Family=inet, Name=MTA-v4, Port=smtp, Addr=0.0.0.0')dnl dnl DAEMON_OPTIONS(`Family=inet6, Name=MSP-v6, Port=submission, M=Ea, Addr=::1')dnl DAEMON_OPTIONS(`Family=inet, Name=MSP-v4, Port=submission, M=Ea, Addr=127.0.0.1')dnl
保存并使之生效:
m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
4.发送方式:
1.如何写一般的邮件: mail test@qq.com Cc 编辑抄送对象,Subject:邮件主题,输入回车,邮件正文后,按Ctrl-D结束 2.快速发送方式: echo “邮件正文” | mail -s "邮件主题" test@126.com 3.以文件内容作为邮件正文来发送: mail -s test test@126.com < test.txt 4.发送带附件的邮件: uuencode 附件名称 附件显示名称 | mail -s 邮件主题 发送地址
5.日志位置:
tail -f /var/log/mail.log
6.sendmail使用的端口为25端口,如未开通防火墙,需打开防火墙和服务云的安全组规则
使用 telnet 外网ip port 查看是否可通;
放开防火墙(如: iptables)
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 25 -j ACCEPT
iptables -L -n
7.可能出现的错误
发送邮件提示: "unable to qualify my own domain name (ecs-df00) -- using short name":
Oct 31 01:21:01 ecs-df00 sm-msp-queue[1406209]: unable to qualify my own domain name (ecs-df00) -- using short name
解决方法: vim /etc/hosts 修改对应服务名为".com"结尾即可
127.0.0.1 localhost # The following lines are desirable for IPv6 capable hosts ::1 localhost ip6-localhost ip6-loopback ff02::1 ip6-allnodes ff02::2 ip6-allrouters 127.0.1.1 localhost.vm localhost 127.0.1.1 ecs-df00.com ecs-df00
到自己邮箱中查看即可发现已收到邮件;
同时可看到日志:
(base) root@ecs-df00:/var/log# tail -f mail.log Nov 3 02:11:01 ecs-df00 sendmail[1454106]: 2A2IB1eT1454106: from=root@ecs-df00.com, size=92, class=0, nrcpts=1, msgid=<202211021811.2A2IB1eT1454106@ecs-df00.com>, relay=root@localhost Nov 3 02:11:01 ecs-df00 sm-mta[1454108]: 2A2IB1Fc1454108: from=<root@ecs-df00.com>, size=340, class=0, nrcpts=1, msgid=<202211021811.2A2IB1eT1454106@ecs-df00.com>, proto=ESMTP, daemon=MTA-v4, relay=localhost [127.0.0.1]
标签:sendmail,dnl,ecs,邮件,ubuntu,mail,安装,df00 From: https://www.cnblogs.com/chencoolandclear/p/16842896.html