# 1.安装msmtp(没有brew的百度一下安装方法)
brew install msmtp
# 2.配置文件(应该是为了替换sendmail)
vi ~/.mailrc
set sendmail=/usr/local/bin/msmtp
wq!
# 3.配置发送邮箱相关参数
vi ~/.msmtprc
# Use an external SMTP server with insecure authentication.
# (manually choose an insecure authentication method.)
# Note that the password contains blanks.
defaults
####################################################################
# A sample configuration using sina.cn
####################################################################
account default
# 配置SMTP服务器(在163邮箱的设置中获取)
host smtp.163.com
# 默认端口
port 25
# 发送邮箱
from wuqiongcus@163.com
auth login
tls off
# 发送人也是邮箱
user wuqiongcus@163.com
# 授权的密码(163邮箱授权时会有提示保存)
password LICEDJLNAJCQPGCF
# 4.测试发送邮件命令(发送邮箱定要同时发给自己,不然可能会报554 DT:SPM 。。。)
# 例子1
ifconfig |mail -s 今日ip wuqiongcus@163.com
# 例子2
echo "你在干什么" |mail wuqiongcus@163.com
# 5.设置定时(mac自带定时)
crontab -e
# 6.编辑命令
# 用于防止shell脚本中的命令无法使用(本次涉及ifconfig命令)
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# 设置定时(其中 2>&1 比较重要,用于获取错误信息)
*/1 * * * * cd /Users/wuqiong/Desktop/tools/sh/sendIpToEmailAutomatically && sh AutoSendIp.sh >> log 2>&1
# 7.设置crontab的访问权限
# 7.1 系统偏好设置 -> 安全性与隐私 -> 隐私 -> 完全磁盘访问权限 -> 解锁 -> 新增
# 7.2 快捷键 cmd + shift + g , 输入 /usr/sbin, 选择 cron 添加即可