【 Linux学习】解决Ubuntu系统发送邮件失败,报错:send-mail: fatal: open /etc/postfix/main.cf: No such file or directory

一、问题描述

今天在Ubuntu系统上,使用mail命令发送邮件的时候,失败了,报错send-mail: fatal: open /etc/postfix/main.cf: No such file or directory。具体信息如下所示:

root@ubuntu186:/data/gitlabDataBackup# echo "Email Content:This is the content of mail. Welcome to ouyangpeng's blog : http://blog.csdn.net/ouyang_peng/" | mail -s "Email Subject : Hello from Linux Server by shell" ouyangpeng@oaserver.dw.gdbbk.com
send-mail: fatal: open /etc/postfix/main.cf: No such file or directory
Can't send mail: sendmail process failed with error code 75
root@ubuntu186:/data/gitlabDataBackup# 

这里写图片描述

二、解决办法

2.1 postfix的配置文件结构

  postfix的配置文件位于/etc/postfix下,安装完postfix以后,我们可以通过ls命令查看postfix的配置文件:

这里写图片描述
上图是我修复该bug之后的完整截图。之前报错就是因为 main.cf文件没有找到。 main.cf文件是postfix主要的配置文件,我们需要重新配置才能生成该配置文件。

postfix最基本的配置文件

  • mail.cf:是postfix主要的配置文件。
  • master.cf:是postfix的master进程的配置文件,该文件中的每一行都是用来配置postfix的组件进程的运行方式。
  • postfix-script:包装了一些postfix命令,以便我们在linux环境中安全地执行这些postfix命令。

2.2 重新配置postfix

输入 dpkg-reconfigure postfix 命令,重新配置 postfix 。

敲完命令,就会弹出如下所示的界面

这里写图片描述

选择【Internet Site】 然后按住【TAB】键,切换之后选择【确认】,然后按住【Enter】键确认

这里写图片描述

接着弹出要输入mail_name页面,输入一个名字即可,如下所示:

扫描二维码关注公众号,回复: 2804607 查看本文章

这里写图片描述

接着会出现一系列需要配置的页面,如下所示,大家选好之后一路确定即可。

这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

都配置完毕之后,会退出配置界面,进入命令行界面,如下所示:

这里写图片描述

root@ubuntu186:/data/gitlabDataBackup# dpkg-reconfigure postfix
setting synchronous mail queue updates: false
setting myhostname: ubuntu186
setting alias maps
setting alias database
mailname is not a fully qualified domain name.  Not changing /etc/mailname.
setting destinations: ubuntu186, localhost.localdomain, , localhost
setting relayhost: 
setting mynetworks: 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
setting mailbox_size_limit: 0
setting recipient_delimiter: +
setting inet_interfaces: all
setting inet_protocols: all
WARNING: /etc/aliases exists, but does not have a root alias.

Postfix is now set up with a default configuration.  If you need to make 
changes, edit
/etc/postfix/main.cf (and others) as needed.  To view Postfix configuration
values, see postconf(1).

After modifying main.cf, be sure to run '/etc/init.d/postfix reload'.

Running newaliases
 * Stopping Postfix Mail Transport Agent postfix                                                                                                                                      [ OK ] 
 * Starting Postfix Mail Transport Agent postfix                                                                                                                                      [ OK ] 
root@ubuntu186:/data/gitlabDataBackup# 

然后再试着看看 能不能发送邮件,如下所示:

root@ubuntu186:/data/gitlabDataBackup# echo "Email Content:This is the content of mail. Welcome to ouyangpeng's blog : http://blog.csdn.net/ouyang_peng/" | mail -s "Email Subject : Hello from Linux Server by shell" ouyangpeng@oaserver.dw.gdbbk.com
root@ubuntu186:/data/gitlabDataBackup# 

这里写图片描述

发现邮件发送成功了,没有报错了。去OA查看下邮件,如下所示:

这里写图片描述

三、总结

出现这个错误,使用 dpkg-reconfigure postfix 命令重新配置好 postfix 即可发送成功,具体的配置根据你们自己的系统来进行配置。

可以参考以下链接来进行自己的postfix配置


这里写图片描述

作者:欧阳鹏 欢迎转载,与人分享是进步的源泉!
转载请保留原文地址:https://blog.csdn.net/ouyang_peng/article/details/81536396

如果觉得本文对您有所帮助,欢迎您扫码下图所示的支付宝和微信支付二维码对本文进行随意打赏。您的支持将鼓励我继续创作

猜你喜欢

转载自blog.csdn.net/qq446282412/article/details/81557321