qq邮箱获取授权码
如图1所示登陆qq邮箱,点击上方设置,点击账号,向下滑动,找到POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV服务 点击开启授权码
网易邮箱获取授权码
- 登陆到网易邮箱中,点击上方设置,选择POP3/SMTP/IMAP,如图1所示
- 开启POP3/SMTP服务或IMAP/SMTP服务协议
- 下面根据提示新增授权码即可
下载mailx服务
输入命令vim /etc/mail.rc
然后把
set from= #你的QQ邮箱或者网易邮箱其他邮箱 set smtp=smtp.qq.com #QQ邮箱就写这个,网易邮箱写smtp.163.com set smtp-auth-user= #发件人,可以自己发给自己 set smtp-auth-password= #邮箱授权码 set smtp-auth=login set ssl-verify=ignore将这些内容添加在行尾
编写脚本
输入命令 vim emailSend.sh
然后编写脚本
#!/bin/bash recipient="recipient@example.com" subject="Test Email" message="Hello, this is a test email sent from a Linux script." # 使用 mail 命令发送邮件 echo "$message" | mail -s "$subject" "$recipient" # 检查邮件是否成功发送 if [ $? -eq 0 ]; then echo "Email sent successfully." else echo "Failed to send email. Please check the error message." firecipient 变量是收件人的电子邮件地址。
subject 变量是邮件的主题。
message 变量包含邮件的正文内容。
使用 echo "$message" | mail -s "$subject" "$recipient" 将邮件正文通过管道传递给 mail 命令,并指定主题和收件人。
发送成功![]()
输入命令 bash emailSend.sh 运行脚本
发送成功
本文转载自DOIT社区
转载自: shell脚本发邮件-DOIT社区https://www.doitwiki.com/article/details/423