簡體   English   中英

發送帶有附件和正文的電子郵件的功能

[英]Function to send e-mail with attachment and body

我按照下面的示例在$ email_template中設置了電子郵件正文,然后想要使用該功能發送帶有附件的電子郵件,例如do_mail attachment.csv user@domain.com

$email_template="Subject: Listing - `date --date="tomorrow" +"%A %d %B %Y"`
From: no-reply@domain.com
To: $2
Content-Type: plain/text

Please see attached listing - `date --date="tomorrow" +"%A %d %B %Y"`
"

do_mail () {
        uuencode $1 $1 | 
        printf "$email_template" "$2" | 
        /usr/sbin/sendmail -oi -t
}

因為沒有發送電子郵件,這有什么錯誤嗎?

據我所知,您想要完成的$2替換尚未完成。 不能在定義字符串時使用它,而是使用printf進行設置,因此模板中應包含%s

其次,管道很奇怪。 我認為,你的意思是

do_mail () {
    {
        printf "$email_template" "$2"
        uuencode "$1" "$1"
    } | /usr/sbin/sendmail -oi -t
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM