命令行发送邮件并修改发送人,避免自动邮件归置到垃圾邮件

1.安装home-brew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

如果安装提示error:

curl: (35) Server aborted the SSL handshake


解决方案:

1.不过安装前,因为OS X El Capitan引入了系统完整性保护机制,使用Homebrew的同学请在升级后执行

sudo chown $(whoami):admin /usr/local && sudo chown -R $(whoami):admin /usr/local

2.在命令中添加 --insecure

/usr/bin/ruby -e "$(curl -fsSL --insecure  https://raw.githubusercontent.com/Homebrew/install/master/install)"  
卸载命令
sudo ruby -e "$(curl -fsSL --insecure https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"


2.安装msmtp

brew install msmtp 


3. 配置

vi ~/.mailrc  

粘贴 

set sendmail=/usr/local/bin/msmtp


vi ~/.msmtprc

注意把邮件密码设置为你的邮箱密码

defaults
logfile ~/.msmtp.log

account honglili@sohu-inc.com
host mail.sohu-inc.com
port 25
auth login
from honglili@sohu-inc.com
user honglili@sohu-inc.com
password *******

# this next line is crucial: you have to point to the correct security certificate for GMail.
# If this doesn't work, check the mstmp documentation
# at http://msmtp.sourceforge.net/documentation.html for help
#
# This next line should all be on one long line:
#tls_trust_file /path/to/Thawte Roots/Thawte SSLWeb Server Roots/thawte Premium Server CA/Thawte Premium Server CA.pem

# Set a default account
# You need to set a default account for Mail
account default : honglili@sohu-inc.com

# end msmtprc

4. ~/.msmtprc 需要设置正确的访问权限
chmod 600 ~/.msmtprc


5.发送邮件

echo 'hello world' | mail -s "Subject" 305897143@qq.com 

mail -s "test mail" 305897143@qq.com  < ./head.jpg

注:-s "Subject" 指修改标题   < ./head.jpg 重定向内容


其他

发送附件:

cat head.jpg| uuencode head.jpg | mail -s "test" 305897143@qq.com





  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值