first SSH to your device, then input the following:
cd /
nano mail.py
change your email, password, recipient and smtp server in the following then paste on terminal (right click on putty):
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from email.header import Header
from email.mime.text import MIMEText
from getpass import getpass
from smtplib import SMTP_SSL
import sys
#edit the line below
login, password, server, recipients = "youremail@gmail.com", "password", "smtp.gmail.com", "recipient@domain.com"
#send email
subject = sys.argv[1]
body = sys.argv[2]
msg = MIMEText(body, 'plain', 'utf-8')
msg['Subject'] = Header(subject, 'utf-8')
msg['From'] = login
msg['To'] = recipients
s = SMTP_SSL(server, 465, timeout=10)
s.set_debuglevel(1)
try:
s.login(login, password)
s.sendmail(msg['From'], recipients, msg.as_string())
except Exception, error:
print "Unable to send e-mail: '%s'." % str(error)
finally:
s.quit()
to save the file, type Ctrl + X , then Y to confirm
you can then use the script as follows:
python mail.py "subject" "message"
or to email the contents of a file (e.g. a log file):
message=`cat file.log`;python mail.py "subject" "$message"