E-Mail with Config DB

Status
Not open for further replies.

hellweiss

Cadet
Joined
Aug 29, 2012
Messages
6
Here's a little Script I copied from some Example Sites and added some Code. It sends an E-Mail with the attached Config DB.
It's provided as it is and it works for me. So as always, no warranties. Perhaps it will be useful for someone.

Code:
#!/usr/bin/env python

import sys
import smtplib
import time
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email import Encoders

HOSTNAME = 'freenas.local' 
SERVER = 'your.mailserver.local'
FROM = 'root@' + HOSTNAME
TO = 'your_mail@localdomain'
SUBJECT = 'Config DB of ' + HOSTNAME
TEXT = 'The Config DB is from ' + time.asctime()
FILENAME = '/data/freenas-v1.db'

#
msg = MIMEMultipart()
msg['Subject'] = SUBJECT
msg['From'] = FROM
msg['To'] = TO

#
part0 = MIMEText(TEXT, 'plain')

#
part1 = MIMEBase('application', "octet-stream")
fp = open(FILENAME, 'rb')
part1.set_payload( fp.read() )
fp.close()
Encoders.encode_base64(part1)
part1.add_header('Content-Disposition', 'attachment; filename="%s"' % FILENAME)

#
msg.attach(part0)
msg.attach(part1)

# 
s = smtplib.SMTP(SERVER)
s.sendmail(FROM, TO, msg.as_string())
s.quit()
 

ProtoSD

MVP
Joined
Jul 1, 2011
Messages
3,348
Just a note of caution, the database contains account and password information for your system & users, email is NEVER secure!

Use caution if you do this.
 

Stephens

Patron
Joined
Jun 19, 2012
Messages
496
Thanks for the warning. In Windows, I'd RAR it with a strong password before e-mailing it. I'm not sure what the FreeBSD equivalent of that would be. I looked at gzip, which I thought was the common method of compression on *NIX but it doesn't seem to support passwords. RAR also supports recovery records so if the archive gets slightly corrupted, it can still be recovered.
 
Status
Not open for further replies.
Top