Bài 16D: Nhúng hình vào email

Khi cài đặt ssmtp mpack, chúng ta có thể gởi email với file kèm. File kèm này phải tải về mới có thể xem được.

Chúng ta cũng có thể nhúng hình vào trong nội dung của email, hình này được tải về cùng lúc với text.

File hình với đường dẫn tuyệt đối là $snapshot
snpshot=$(basename $snapshot)

sendmail -t <<EOT
TO: $mail_to
FROM: Raspbery Pi' s Administrator <mailman@lyle.info>
SUBJECT: Camera Alert
MIME-Version: 1.0
Content-Type: multipart/related;boundary="Boundary-Here"

--Boundary-Here
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<img align="center" src="cid:$spshot" alt=""><br /><br />
Các nội dung khác ở đây
</body>
</html>

--Boundary-Here
Content-Type: image/jpeg;name="$snapshot"
Content-Transfer-Encoding: base64
Content-ID: <$spshot>
Content-Disposition: inline; filename="$spshot"

$(base64 $snapshot)
--Boundary-Here--
EOT

	

Leave a Comment

Filed under Software

Leave a Reply

Your email address will not be published. Required fields are marked *