2011-03-22 9 views
8

HTML本文をメッセージ本文として送信し、このメールメッセージに複数のテキストファイルを添付したいとします。sendmailを使用して複数のテキスト添付ファイルを含むHTML本文メールを送信する方法

htmlファイルを送信する必要があるため、sendmailを使用する必要があります(mailxを使用してできませんでした)。

どのようにHTML本文メールと複数のテキスト添付ファイルをsendmailで送信しますか?

答えて

0

私はsendmailがそれを手伝ってくれるとは思いません。 muttのようなクライアントに行く。 mutt -a file1 -a file2 -- [email protected]。またはperlに行きます。あなたは、このような複数の添付ファイルを含む電子メールを送信することができ、あなたのシステムで利用可能なuunecodeを持っていると仮定すると

+0

ないすべてのシステムは、雑種犬をインストールする機能を持っていますので、質問は尋ねたとして:) – stevepastelan

+0

Sendmailの@stevepastelan単に行うことができないあなたのアドバイスは、sendmailのかのmailxを使用する必要がある誰かに非常に有用ではありませんそれは追加ツールなしで。あなたが選ぶツールはもちろんあなた次第です。 – ShiDoiSi

+1

もちろん、sendmail *はできます。これは、sendmailに渡すためにコンテンツをどのようにフォーマットするかという問題です。 – stevepastelan

9

#!/bin/bash 

... 
... 
... 
BOUNDARY="=== This is the boundary between parts of the message. ===" 

{ 
    echo "From: $MAILFROM" 
    echo "To: $MAILTO" 
    echo "Subject:" $SUBJECT 
    echo "MIME-Version: 1.0" 
    echo "Content-Type: MULTIPART/MIXED; " 
    echo " BOUNDARY="\"$BOUNDARY\" 
    echo 
    echo "  This message is in MIME format. But if you can see this," 
    echo "  you aren't using a MIME aware mail program. You shouldn't " 
    echo "  have too many problems because this message is entirely in" 
    echo "  ASCII and is designed to be somewhat readable with old " 
    echo "  mail software." 
    echo 
    echo "--${BOUNDARY}" 
    echo "Content-Type: TEXT/PLAIN; charset=US-ASCII" 
    echo 
    echo "This email comes with multiple attachments." 
    echo 
    echo 
    echo "--${BOUNDARY}" 
    echo "Content-Type: application/zip; charset=US-ASCII; name="${ZIPFILE} 
    echo "Content-Disposition: attachment; filename="`basename ${ZIPFILE}` 
    echo 
    uuencode $ZIPFILE $ZIPFILE 
    echo 
    echo "--${BOUNDARY}--" 
    echo "Content-Type: application/pdf; charset=US-ASCII; name="${PDFFILE} 
    echo "Content-Disposition: attachment; filename="`basename ${PDFFILE}` 
    echo 
    uuencode $PDFFILE $PDFFILE 
    echo 
    echo "--${BOUNDARY}--" 
} | /usr/lib/sendmail -t 
+0

上記の方法で送信されたメールは添付ファイルで送信できますが、Outlookのメールクライアントではエンコードされたファイルとして受信されます。受信者側でデコードされたファイルとして受信するようにファイルを送信するには? – greperror

0

ここでは、私は人々に生成するレポートを送信するために使用bashスクリプトです。それらは添付ファイルとして送信されます。 HTMLをスクリプトの "body"変数に置きます。私は変数のパラメータ化をあなたに任せます。

#!/bin/bash 

function get_mimetype(){ 
file --mime-type "$1" | sed 's/.*: //' 
} 

from="[email protected]" 
to="[email protected]" 
subject="Your Report my Lord" 
boundary="=== Boundary ===" 
body="The reports are attached to this email" 
declare -a attachments 
attachments=("fileOne.out" "fileTwo.out" "fileThree.out" "file-et-cetera.out") 

# Build headers 
{ 

printf '%s\n' "From: $from 
To: $to 
Subject: $subject 
Mime-Version: 1.0 
Content-Type: multipart/mixed; boundary=\"$boundary\" 

--${boundary} 
Content-Type: text/plain; charset=\"US-ASCII\" 
Content-Transfer-Encoding: 7bit 
Content-Disposition: inline 

$body 
" 

for file in "${attachments[@]}"; do 

     [ ! -f "$file" ] && echo "Attachment $file not found, omitting file" >&2 && continue 

     mimetype=$(get_mimetype "$file") 

    printf '%s\n' "--${boundary} 
Content-Type: $mimetype 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment; filename=\"$file\" 
    " 

    base64 "$file" 
    echo 
done 

# print last boundary with closing -- 
printf '%s\n' "--${boundary}--" 

} | sendmail -t -oi 
関連する問題