zoukankan      html  css  js  c++  java
  • 使用sendmail命令发送附件

    在自动化中经常需要将日志文件发送到指定用户组,于是记录一下使用sendmail发送邮件及附件的shell脚本模板

    #!/bin/bash
    MAILFROM="noreply@`hostname -f`"
    MAILTO="mail.to@hotmail.com"
    SUBJECT="Sendmail templete test"
    ATTACHMENT="XXXXXXX20190227.log"
    MAILPART=`uuidgen` ## Generates Unique ID as boundary
    MAILPART_BODY=`uuidgen` ## Generates Unique ID as boundary
    
    (
     echo "From: $MAILFROM"
     echo "To: $MAILTO"
     echo "Subject: $SUBJECT"
     echo "MIME-Version: 1.0"
     echo "Content-Type: multipart/mixed; boundary="$MAILPART""
     echo ""
     echo "--$MAILPART"
     echo "Content-Type: multipart/alternative; boundary="$MAILPART_BODY""
     echo ""
     echo "--$MAILPART_BODY"
     echo "Content-Type: text/plain; charset=UTF-8"
     echo "This is TEXT part and below is HTML part"
     echo "--$MAILPART_BODY"
     echo "Content-Type: text/html; charset=UTF-8"
     echo ""
     echo "<html><body><div>THIS IS HTML PART</div></body></html>"
     echo "--$MAILPART_BODY--"
    
     echo "--$MAILPART"
     echo 'Content-Type: text/plain; name="'$(basename $ATTACHMENT)'"'
     echo "Content-Transfer-Encoding: base64"
     echo ""
     openssl base64 < $ATTACHMENT;
     echo "--$MAILPART--"
    )  | sendmail -t
    
  • 相关阅读:
    Linux 的硬链接与软链接
    Django补遗(一)
    Django之Form组件
    Django进阶(三)
    Django进阶(二)
    Web请求提交页面--防重提交
    Lucene的搭建(3)
    Lucene的搭建(2)
    Redis-cluster集群搭建
    Redis安装
  • 原文地址:https://www.cnblogs.com/lestatzhang/p/10611323.html
Copyright © 2011-2022 走看看