Files
Email_text_file/send_mail.py

64 lines
1.5 KiB
Python
Raw Normal View History

2022-04-14 10:02:48 +00:00
#!/usr/bin/env python
# This script sends an email with N last bytes from file X,
# X and N are given has command line arguments.
#
2023-05-28 11:57:19 +02:00
# By Jony Silva
2022-04-14 10:02:48 +00:00
# Wed 25 Nov 20:30:25 GMT 2015
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
#
# enjoy :)
import smtplib
import sys
# Variables
RTYPE = sys.argv[1]
LINES = int(sys.argv[2])
# Send the email routine
def mail_send():
fromaddr = 'xxxxx@gmail.com'
toaddrs = 'xxxxxx@yahoo.com'
msg = 'Subject: Report\n\n%s' % (TEXT)
# Credentials
username = 'xxxxxx'
password = 'xxxxxxxxxxx'
# The actual mail send
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login(username,password)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()
print "Report done and sent."
# Grab last n bytes of text from the file
f = open(RTYPE, 'r')
f.seek(-LINES, 2)
TEXT = f.read(LINES)
f.close()
mail_send()
#print TEXT