命令行下如何发邮件

前几天,由于业务需要,学习了下命令行下如何发送邮件,总结成本文。

  1. 首先,安装mailx

    $ yum install mailx
  2. 其次,配置服务

    
    # /etc/mail.rc 
    
    ignore mime-version content-transfer-encoding
    
    
    # Only include selected header fields when forwarding messages.
    
    fwdretain subject date from to
    
    
    # For Linux and BSD, this should be set.
    
    set bsdcompat
    
    set from=sky-notify@yhd.com
    set smtp= mail.hotdian.com.cn

    配置邮件源地址(发送给对方时,显示的发件人)
    配置邮件服务器地址

    这样就可以使用mail命令发邮件了。

  3. 发邮件

    方式一:

    $ echo "hello" | mail -s "Hello from me" lanyang@hotdian.com

    ‘-s’ 是邮件主题,后面紧跟收件人地址

    方式二:
    从文件读取发送内容

    $ mail -s "look at this" lanyang@hotdian.com < mail_content.txt
  4. 问题

    问题1:

    send-mail: warning: inet_protocols: IPv6 support is disabled:Address family not supported by protocol
    send-mail: warning: inet_protocols: configuring for IPv4 supportonly
    postdrop: warning: inet_protocols: IPv6 support is disabled:Address family not supported by protocol
    postdrop: warning: inet_protocols: configuring for IPv4 supportonly

    解决办法:

    
    # vi /etc/postfix/main.cf
    
    inet_protocols = all
    改为
    inet_protocols = ipv4

    问题2:
    不支持中文,尚未解决。sendmail似乎支持,待后续验证。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值