Page 1 of 2

[PP-Script] SendFiles - send downloaded files via email

Posted: 01 Jun 2013, 15:42
by hugbug
The script checks if download has files with certain extensions and sends them via email (one email per file).

Sendfiles.py

Posted: 27 Jan 2015, 22:14
by mikool22
Hello All

I have installed the sendfiles.py which is working great for files which are under 25mb which I can send via my gmail account however does anyone have any good solution for sending larger files?

Are there any free email services which allow large file attachements?

Thanks
Michael

Re: [PP-Script] SendFiles - send downloaded files via email

Posted: 27 Jan 2015, 22:48
by hugbug
How big are your files?
For very large files (for example video) email isn't an option. The solotion depends on your target device/platform. The files can be transferred via ftp (I believe there was a script for that) or rsync.
If target isn't always onlne something like dropbox could be a possible solution. I didn't saw a pp-script for that but that might work without a special dropbox-script if you can get the files copied into the sync folder. Although you may need a simple script to copy the files.

Besides the SendFiles-script isn't designed to send really big files. It loads the whole file into memory and encodes it into email-format as a whole requiring much more memory for this again. To send 100MB it may use 500MB of memory or more, I don't know exact numbers but they are high and that can become an issue.

Re: [PP-Script] SendFiles - send downloaded files via email

Posted: 27 Jan 2015, 22:58
by mikool22
Hi,

The files I am sending are on average 70mb - these are some magazines that I want to be able to view on my iphone when im out and about without having to preload.

I guess I could sync these into a googledrive or sync a drop box. Might be a better solution!

Re: [PP-Script] SendFiles - send downloaded files via email

Posted: 29 Jan 2015, 22:16
by mikool22
Hi hugbug - I have looked at the google drive option and it seems to be the best but I am not sure if the facility is there within that application to sync folders outside of the google drive folder. Is there a script created to copy files from one directory to another?

Re: [PP-Script] SendFiles - send downloaded files via email

Posted: 29 Jan 2015, 22:36
by hugbug

Re: [PP-Script] SendFiles - send downloaded files via email

Posted: 26 May 2015, 00:52
by thebigslicksuitd
I'm getting a syntax error - here is my file, could someone please help?

Code: Select all

#!/usr/bin/env python
#
# Send files post-processing script for NZBGet
#
# Copyright (C) 2013 Andrey Prygunkov <hugbug@users.sourceforge.net>
#
# 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 2 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#
# $Revision: 660 $
# $Date: 2013-05-02 22:40:36 +0200 (Do, 02 Mai 2013) $
#


##############################################################################
### NZBGET POST-PROCESSING SCRIPT                                          ###

# Send files via e-mail.
#
# This script sends downloaded files with specific extensions via e-mail.
#
# NOTE: This script requires Python to be installed on your system.

##############################################################################
### OPTIONS                                                       ###

# Email address you want the emails to be sent from. 
From=myuser@mydomain.com

# Email address you want the emails to be sent to. 
To=myuser2@gmail.com

# SMTP server host.
Server=smtp.gmail.com

# SMTP server port (1-65535).
Port=587

# Secure communication using TLS/SSL (yes, no).
Encryption=yes

# SMTP server user name, if required.
Username=myuser@mydomain.com

# SMTP server password, if required.
Password=mypassword

# Extensions of files to be send.
#
# Only files with these extensions are processed. Extensions must
# be separated with commas.
# Example=.mobi,.epub
Extensions=.epub

### NZBGET POST-PROCESSING SCRIPT                                          ###
##############################################################################


import os
import sys
import datetime
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email import Encoders
try:
	from xmlrpclib import ServerProxy # python 2
except ImportError:

	from xmlrpc.client import ServerProxy # python 3

# Exit codes used by NZBGet
POSTPROCESS_SUCCESS=93
POSTPROCESS_ERROR=94
POSTPROCESS_NONE=95

# Check if the script is called from nzbget 11.0 or later
if not 'NZBOP_SCRIPTDIR' in os.environ:
	print('*** NZBGet post-processing script ***')
	print('This script is supposed to be called from nzbget (11.0 or later).')
	sys.exit(POSTPROCESS_ERROR)

if not os.path.exists(os.environ['NZBPP_DIRECTORY']):
	print('Destination directory doesn\'t exist, exiting')
	sys.exit(POSTPROCESS_NONE)

# Check par and unpack status for errors
if os.environ['NZBPP_PARSTATUS'] == '1' or os.environ['NZBPP_PARSTATUS'] == '4' or os.environ['NZBPP_UNPACKSTATUS'] == '1':
	print('[WARNING] Download of "%s" has failed, exiting' % (os.environ['NZBPP_NZBNAME']))
	sys.exit(POSTPROCESS_NONE)

required_options = ('NZBPO_FROM', 'NZBPO_TO', 'NZBPO_SERVER', 'NZBPO_PORT', 'NZBPO_ENCRYPTION',
	'NZBPO_USERNAME', 'NZBPO_PASSWORD', 'NZBPO_EXTENSIONS')
for	optname in required_options:
	if (not optname in os.environ):
		print('[ERROR] Option %s is missing in configuration file. Please check script settings' % optname[6:])
		sys.exit(POSTPROCESS_ERROR)

def sendfile(filename):
	# Create message
	msg = MIMEMultipart()
	msg['Subject'] = 'Downloaded file %s ' % os.path.splitext(os.path.basename(filename))[0]
	msg['From'] = os.environ['NZBPO_FROM']
	msg['To'] = os.environ['NZBPO_TO']

	text = 'Downloaded file %s\n\n' % os.path.basename(filename)
	msg.attach(MIMEText(text))

	part = MIMEBase('application', 'octet-stream')
	part.set_payload(open(filename, 'rb').read())
	Encoders.encode_base64(part)
	part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(filename))
	msg.attach(part)
	
	# Send message
	print('[INFO] Sending %s' % os.path.basename(filename))
	sys.stdout.flush()
	try:
		smtp = smtplib.SMTP(os.environ['NZBPO_SERVER'], os.environ['NZBPO_PORT'])
		if os.environ['NZBPO_ENCRYPTION'] == 'yes':
			smtp.starttls()
		if os.environ['NZBPO_USERNAME'] != '' and os.environ['NZBPO_PASSWORD'] != '':
			smtp.login(os.environ['NZBPO_USERNAME'], os.environ['NZBPO_PASSWORD'])
		smtp.sendmail(os.environ['NZBPO_FROM'], os.environ['NZBPO_TO'], msg.as_string())
		smtp.quit()
	except Exception as err:
		print('[ERROR] %s' % err)
		sys.exit(POSTPROCESS_ERROR)

# search files
Extensions = os.environ['NZBPO_EXTENSIONS']
Extensions = Extensions.split(',')
cnt = 0
for dirname, dirnames, filenames in os.walk(os.environ['NZBPP_DIRECTORY']):
	for filename in filenames:
		extension = os.path.splitext(filename)[1]
		if extension.lower() in Extensions:
			name = os.path.join(dirname, filename)
			sendfile(unicode(name))
			cnt += 1

if cnt > 0:
	print('Sent %i file(s)' % cnt)
	sys.exit(POSTPROCESS_SUCCESS)
else:
	print('No suitable files found')
	sys.exit(POSTPROCESS_NONE)

Re: [PP-Script] SendFiles - send downloaded files via email

Posted: 26 May 2015, 05:09
by hugbug
No need to post the script which we already have. Better post the error message.

Re: [PP-Script] SendFiles - send downloaded files via email

Posted: 26 May 2015, 14:08
by l2g
thebigslicksuitd: I think if you were to just download the script and not make any changes to it; just copy it straight into you nzbget/scripts folder as you received it. The changes and settings you want to make are done through the NZBGet (web page) configuration screen. You don't directly want to modify the script itself (ever).

Re: [PP-Script] SendFiles - send downloaded files via email

Posted: 17 Jun 2015, 09:13
by thebigslicksuitd
hugbug wrote:No need to post the script which we already have. Better post the error message.

Code: Select all

ERROR	Tue Jun 16 2015 23:08:43	Post-process-script SendFiles.py for [mybook] (epub) failed (terminated with unknown status)
INFO	Tue Jun 16 2015 23:08:43	SendFiles: ImportError: cannot import name 'Encoders'
INFO	Tue Jun 16 2015 23:08:43	SendFiles: from email import Encoders
INFO	Tue Jun 16 2015 23:08:43	SendFiles: File "/data/scripts/SendFiles.py", line 77, in <module>
INFO	Tue Jun 16 2015 23:08:43	SendFiles: Traceback (most recent call last):
INFO	Tue Jun 16 2015 23:08:43	Executing post-process-script SendFiles.py
l2g wrote:thebigslicksuitd: I think if you were to just download the script and not make any changes to it; just copy it straight into you nzbget/scripts folder as you received it. The changes and settings you want to make are done through the NZBGet (web page) configuration screen. You don't directly want to modify the script itself (ever).
I re-did the script as you suggested and get the above error.

Thanks!