Send Emails From XBMC!
#1
Hello all,

I thought that i would share a little script that i made that will allow you to send emails from XBMC using python.

It's only a small script but it works perfectly for me!


Here is the python script that will send the emails :

PHP Code:
import smtplib
 
to 
xbmc.getInfoLabel'$INFO[Skin.string(EmailTo)]' )
gmail_user xbmc.getInfoLabel'$INFO[Skin.string(MyEmail)]' )
gmail_pwd xbmc.getInfoLabel'$INFO[Skin.string(MyPassword)]' )
msg xbmc.getInfoLabel'$INFO[Skin.string(MyMessage)]' )
sub xbmc.getInfoLabel'$INFO[Skin.string(MySubject)]' )
smtpserver smtplib.SMTP("smtp.gmail.com",587)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo
smtpserver
.login(gmail_usergmail_pwd)
header 'To:' to '\n' 'From: ' gmail_user '\n' 'Subject:' sub '\n'
print header
msg 
header '\n' msg '\n\n'
smtpserver.sendmail(gmail_usertomsg)
print 
'done!'
smtpserver.close() 



And here is how you set your email address that you will send it from :
PHP Code:
Skin.SetString(MyEmail

And your password :
PHP Code:
Skin.SetString(MyPassword

When sending an email you can input the email address by using :
PHP Code:
Skin.SetString(EmailTo

For the email's subject you can use
PHP Code:
Skin.SetString(MySubject

And as for the actual message you can just use :
PHP Code:
Skin.SetString(MyMessage


Feel free to change anything around and integrate this in to any of your plugins/skins or whatever Smile
Reply
#2
I have recently changed around some of the things in there so that it will now work with any email address.

Here is the script for anyone that is interested :

PHP Code:
import smtplib
 
to 
xbmc.getInfoLabel'$INFO[Skin.string(EmailTo)]' )
gmail_user xbmc.getInfoLabel'$INFO[Skin.string(MyEmail)]' )
gmail_pwd xbmc.getInfoLabel'$INFO[Skin.string(MyPassword)]' )
msg xbmc.getInfoLabel'$INFO[Skin.string(MyMessage)]' )
sub xbmc.getInfoLabel'$INFO[Skin.string(MySubject)]' )
server xbmc.getInfoLabel'$INFO[Skin.string(EmailServer)]' )
port xbmc.getInfoLabel'$INFO[Skin.string(ServerPort)]' )
smtpserver smtplib.SMTP(server,port)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo
smtpserver
.login(gmail_usergmail_pwd)
header 'To:' to '\n' 'From: ' gmail_user '\n' 'Subject:' sub '\n'
print header
msg 
header '\n' msg '\n\n'
smtpserver.sendmail(gmail_usertomsg)
print 
'done!'
smtpserver.close() 


And to set the email type and port just use :

PHP Code:
Skin.SetString(ServerPortPORT)
Skin.SetString(EmailServerSERVER

But change around the PORT and SERVER to what you want.

For example to use Hotmail you could use :

PHP Code:
Skin.SetString(ServerPort25)
Skin.SetString(EmailServersmtp.live.com
Reply
#3
Can this script also be used as standalone?
For example I use msmtp to send mail. On openelec there is no 'mail sender' included so it can not be used.

My script does the html and then uses msmtp to send mail. How would it be possible to use your script to replace msmtp?

Code:
#!/bin/sh
# Send mail when download finished
FROMNAME="Linksys E3000 Router"
torrent_name="$TR_TORRENT_NAME"
torrent_version="$TR_APP_VERSION"

echo MIME-Version: 1.0 >/tmp/tmail.html
echo Content-Type: text/html >>/tmp/tmail.html
echo "Subject: "$TR_TORRENT_NAME" Downloaded" >>/tmp/tmail.html
echo "From: \\"$FROMNAME\\"<$FROM>" >>/tmp/tmail.html
echo "Date: `date -R`" >>/tmp/tmail.html
echo "" >>/tmp/tmail.html
echo "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">" >>/tmp/tmail.html
echo "<html>" >>/tmp/tmail.html
echo "<head><title></title>" >>/tmp/tmail.html
echo "</head>" >>/tmp/tmail.html
echo "<p>Transmission v"$torrent_version" finished downloading:</p>" >>/tmp/tmail.html
echo "<p><b>"$TR_TORRENT_NAME"<b></p>" >>/tmp/tmail.html
echo "<p>on `date +\%d/\%m/\%Y` at `date +\%T`</p>" >>/tmp/tmail.html
echo "" >>/tmp/tmail.html
echo "<p>From Linksys E3000 Router.</p>" >>/tmp/tmail.html
echo "<a href="http://bite-in.com/siol/transmission_icon.png" target="_blank"><img src="http://bite-in.com/siol/transmission_icon.png" border="0" alt="Image hosted by Bite-in.com"></a>" >>/tmp/tmail.html
echo "</body>" >>/tmp/tmail.html
echo "</html>" >>/tmp/tmail.html
cat /tmp/tmail.html | msmtp -a default [email protected]
rm /tmp/tmail.html
Reply
#4
Would be ideal,if you could provide somewhat more information on how and where to apply these settings in XBMC
Reply

Logout Mark Read Team Forum Stats Members Help
Send Emails From XBMC!0