Wrote this for a cronjob on my server, it might be useful for you.
#!/usr/bin/python
import os
import sys
import smtplib
# For guessing MIME type based on file name extension
import mimetypes
from optparse import OptionParser
from email import encoders
from email.message import Message
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
import time
import Crypto.Cipher.AES as AES
import hashlib
import jsonrpc
import random
PASSWORD = "ENCRYPTION PASSWORD"
BITCOIN_USER = ""
BITCOIN_PASS = "BITCOIND PASSWORD"
TO_EMAIL = "
[email protected]"
DECRYPT_SCRIPT = """#!/usr/bin/python
import Crypto.Cipher.AES as AES
import hashlib
DATA = "%s"
CKSUM = "%s"
PASSWORD = raw_input("Password: ")
OUTPUTFILE = raw_input("Output file: ")
KEY = hashlib.sha256(PASSWORD).digest()
CRYPTER = AES.new(KEY, AES.MODE_CFB)
decrypted_data = CRYPTER.decrypt(DATA.decode("hex"))
if hashlib.sha256(decrypted_data).digest() == CKSUM.decode("hex"):
open(OUTPUTFILE, "w").write(decrypted_data)
print "wallet decrypted!"
else:
print "Wrong password(cksum wrong)"
"""
BITCOIN_ACCESS = jsonrpc.ServiceProxy("http://%s:%
[email protected]:8332"%(BITCOIN_USER, BITCOIN_PASS))
TEMPFILE = "/tmp/wallet.tmp.%d"%random.randint(0,2**23)
HOSTNAME = open("/etc/hostname").readline().strip("\n")
DATESTRING = time.ctime(time.time())
KEY = hashlib.sha256(PASSWORD).digest()
CRYPTER = AES.new(KEY, AES.MODE_CFB)
msg = MIMEMultipart()
msg['Subject'] = "Wallet Backup from %s on %s" %(HOSTNAME, DATESTRING)
msg['To'] = TO_EMAIL
msg['From'] = "walletbackup@%s" % HOSTNAME
BITCOIN_ACCESS.backupwallet(TEMPFILE)
walletdata = open(TEMPFILE, "r").read()
cksum = hashlib.sha256(walletdata).digest()
wallet = CRYPTER.encrypt(walletdata)
wallet_attachment = MIMEBase("application", "octet-stream")
wallet_attachment.set_payload(DECRYPT_SCRIPT % (wallet.encode("hex"), cksum.encode("hex")))
wallet_attachment.add_header('Content-Disposition', 'attachment', filename="decrypter.py")
encoders.encode_base64(wallet_attachment)
msg.attach(wallet_attachment)
#print msg.as_string()
s = smtplib.SMTP('localhost')
s.sendmail("walletbackup@%s" % HOSTNAME, TO_EMAIL, msg.as_string())
s.quit()