package require base64
set SNAPSHOT_URL "
IP DER KAMERA OHNE "http://" DAVORORT/snapshot.cgi?user=
USERNAME&pwd=
PASSWORT"
set EMAIL_SUBJECT "
MAIL BETREFF"
set EMAIL_BODY "
TEXT IN DER MAIL"
set SEND_TO "
EMPFÄNGERADRESSE"
set SEND_FROM "ABSENDEADRESSE"
set SMTP_HOST "
SMTP SERVER ADRESSE"
set SMTP_USER "
SMTP USER NAME, MEIST IDENTISCH MIT DER ABSENDEADRESSE"
set SMTP_PASSWD "
SMTP PASSWORT"
set SMTP_DOMAIN "
SMTP SERVER ADRESSE"
# DEFINE EMAIL TEMPLATE
set tmpl "To: $SEND_TO
From: $SEND_FROM
Subject: $EMAIL_SUBJECT
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=\"=_542bc72c.5lV8m7jWYOrj//k2cdijZPr9Fjy8v4J0l/m4onTDRLUmUDMk\"
--=_542bc72c.5lV8m7jWYOrj//k2cdijZPr9Fjy8v4J0l/m4onTDRLUmUDMk
Content-Type: text/plain; charset=\"iso-8859-1\"
Content-Transfer-Encoding: 8bit
$EMAIL_BODY
--=_542bc72c.5lV8m7jWYOrj//k2cdijZPr9Fjy8v4J0l/m4onTDRLUmUDMk
Content-Type: application/octet-stream; name=\"photo.jpg\"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=\"photo.jpg\"
{IMGDATA}
--=_542bc72c.5lV8m7jWYOrj//k2cdijZPr9Fjy8v4J0l/m4onTDRLUmUDMk--"
# DOWNLOAD THE SNAPSHOT
exec wget -q -O /tmp/snapshot.jpg $SNAPSHOT_URL
# READ SNAPSHOT INTO VARIABLE & BASE64 ENCODE
set fp [open "/tmp/snapshot.jpg" r]
fconfigure $fp -translation binary
set imgdata [read $fp]
set encodeddata [::base64::encode $imgdata]
close $fp
# REPLACE IMG DATA WITH REAL IMAGE DATA
regsub -all "{IMGDATA}" $tmpl $encodeddata tmpl
# WRITE READY EMAIL TO A TMP FILE
set fp [open "/tmp/ready.eml" w]
puts $fp $tmpl
close $fp
set config "
defaults
tls on
tls_certcheck off
logfile /var/log/email.log
account provider
host $SMTP_HOST
from $SEND_FROM
domain $SMTP_DOMAIN
auth login
user $SMTP_USER
password $SMTP_PASSWD
account default: provider
"
set fp [open "/tmp/msmtp.conf" w]
puts $fp $config
close $fp
exec chmod 0600 /tmp/msmtp.conf
# SEND EMAIL USING MSMTP
exec cat /tmp/ready.eml | msmtp -C /tmp/msmtp.conf $SEND_TO
# CLEAN UP
exec rm -f /tmp/msmtp.conf
exec rm -f /tmp/ready.eml
exec rm -f /tmp/snapshot.jpg