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

Share your scripts or request scripts with specific features.
Forum rules
Please keep the forum clean - one topic per script. Questions not related to a specific script should be posted in Support forum.
hugbug
Developer & Admin
Posts: 7401
Joined: 09 Sep 2008, 11:58
Location: Germany

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

Post by hugbug » 01 Jun 2013, 15:42

The script checks if download has files with certain extensions and sends them via email (one email per file).
Attachments
SendFiles.py
(5.15 KiB) Downloaded 409 times

mikool22
Posts: 3
Joined: 27 Jan 2015, 22:10

Sendfiles.py

Post by mikool22 » 27 Jan 2015, 22:14

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

hugbug
Developer & Admin
Posts: 7401
Joined: 09 Sep 2008, 11:58
Location: Germany

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

Post by hugbug » 27 Jan 2015, 22:48

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.

mikool22
Posts: 3
Joined: 27 Jan 2015, 22:10

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

Post by mikool22 » 27 Jan 2015, 22:58

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!

mikool22
Posts: 3
Joined: 27 Jan 2015, 22:10

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

Post by mikool22 » 29 Jan 2015, 22:16

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?

hugbug
Developer & Admin
Posts: 7401
Joined: 09 Sep 2008, 11:58
Location: Germany

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

Post by hugbug » 29 Jan 2015, 22:36


thebigslicksuitd
Posts: 2
Joined: 26 May 2015, 00:48

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

Post by thebigslicksuitd » 26 May 2015, 00:52

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)

hugbug
Developer & Admin
Posts: 7401
Joined: 09 Sep 2008, 11:58
Location: Germany

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

Post by hugbug » 26 May 2015, 05:09

No need to post the script which we already have. Better post the error message.

l2g
Posts: 222
Joined: 27 Jun 2014, 22:13
Contact:

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

Post by l2g » 26 May 2015, 14:08

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).

thebigslicksuitd
Posts: 2
Joined: 26 May 2015, 00:48

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

Post by thebigslicksuitd » 17 Jun 2015, 09:13

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!

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest