使用shell脚本发送HTML邮件,可以使用命令行工具sendEmail
或者mutt
。首先,需要确保这些工具已经安装在你的系统上。以下是使用sendEmail
和mutt
发送HTML邮件的方法:
sendEmail
发送HTML邮件:安装sendEmail
:
sudo apt-get install sendEmail
使用sendEmail
发送HTML邮件:
sendEmail -f from@example.com -t to@example.com -u "Subject" -m "This is the message body." -s smtp.example.com:587 -xu username -xp password -o tls=yes
mutt
发送HTML邮件:安装mutt
:
sudo apt-get install mutt
使用mutt
发送HTML邮件:
mutt -s "Subject" -c "to@example.com" -b "bcc@example.com" -H "Content-Type: text/html" -a /path/to/attachment.html -- from@example.com < /path/to/email_body.html
在这些命令中,你需要替换from@example.com
、to@example.com
、bcc@example.com
、Subject
、/path/to/attachment.html
、/path/to/email_body.html
等参数。
创建一个名为send_html_email.sh
的shell脚本文件,并将以下内容粘贴到文件中:
#!/bin/bash
# Replace these variables with your own values
FROM="from@example.com"
TO="to@example.com"
SUBJECT="Subject"
SMTP_SERVER="smtp.example.com"
SMTP_PORT="587"
USERNAME="username"
PASSWORD="password"
HTML_BODY="/path/to/email_body.html"
# Send the email using sendEmail
sendEmail -f $FROM -t $TO -u $SUBJECT -m "$(cat $HTML_BODY)" -s $SMTP_SERVER:$SMTP_PORT -xu $USERNAME -xp $PASSWORD -o tls=yes
将脚本文件设置为可执行:
chmod +x send_html_email.sh
运行脚本:
./send_html_email.sh
这个脚本将使用sendEmail
工具发送HTML邮件。你需要根据你的实际情况替换脚本中的变量。
领取专属 10元无门槛券
手把手带您无忧上云