Python: multiple email recipients


 
Thread Tools Search this Thread
Top Forums Programming Python: multiple email recipients
# 1  
Old 12-08-2009
Python: multiple email recipients

I am using a the following backup script to backup a server to USB.

USBBackupScript - RdiffBackupWiki

However I don't know python and would like to alter the script so I can send emails about the success or failure of the backup to multiple recipients.

I did do some research but the limit of my expertise is bash scripts at present and so I would appreciate some help.

The relevant code sections from the script are:

Code:
def emailReport(report):
        msg = email.MIMEMultipart.MIMEMultipart()
        msg["To"] = config["email.to"]
        msg["From"] = config["email.from"]
        if (report.success):
                msg["Subject"] = config["email.subject"] + " - SUCCESS"
        else:
                msg["Subject"] = config["email.subject"] + " - FAILURE"
        if (dryrun):
                msg["Subject"] += " *** DRY RUN ONLY ***"
        msg.preamble = "Mime message\n"
        msg.epilogue = ""

        msgBody = email.MIMEText.MIMEText(report.email)
        msg.attach(msgBody)

        logAttachment = email.MIMEText.MIMEText(report.log)
        logAttachment.add_header("Content-disposition", "attachment", filename="backup_log.txt")
        msg.attach(logAttachment)

        smtp = smtplib.SMTP(config["email.smtp_server"])
        smtp.sendmail(config["email.from"], config["email.to"], msg.as_string())
        smtp.quit()

And the config's are read from the ini file, specifically:

Code:
[email]
# enable sending of reports by email
enable = yes
# from and to addresses
from = rdiff-backup-usb@example.com
to = backupmaster@example.com
# base subject line for the email
subject = Backup: MYSERVER
smtp_server = localhost

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Xargs to call python executable to process multiple bam files

I am running the below loop that to process the 3 bam files (which isn't always the case). A .py executable is then called using | xargs sh to further process. If I just run it with echo the output is fine and expected, however when | xargs sh is added I get the error. I tried adding | xargs... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. Shell Programming and Scripting

Python GNU parallel single command on multiple cores

Hello, I have a 4 core machine. Here is my initial script cd /work/ python script.py input.txt output.txt 1 2 3 This script runs for 1.5hrs. So I read across the web and figured out that you can use GNU parallel to submit multiple jobs using parallel. But I am not sure if I can run... (4 Replies)
Discussion started by: jacobs.smith
4 Replies

3. Shell Programming and Scripting

Python passing multiple parameters to functions

Hi, I am a beginner in python programming. In my python script have a main function which calls several other functions. The main function gets its input by reading lines from a input text file. I call the main function for every line in input text file through a loop. def main(line): var1... (6 Replies)
Discussion started by: ctrld
6 Replies

4. UNIX for Dummies Questions & Answers

Problem getting mailx to send true Bcc mail to multiple recipients

I am having trouble getting mailx to send multiple Bcc mails out without everyone in the list of recipients seeing everyone else's email addresses. I looked at the man pages of my system and seem to be following the syntax correctly, but the mails still go out as if I were just putting in a list of... (7 Replies)
Discussion started by: legrandtimonier
7 Replies

5. Shell Programming and Scripting

Bash script with python slicing on multiple data files

I have 2 files generated in linux that has common output and were produced across multiple hosts with the same setup/configs. These files do some simple reporting on resource allocation and user sessions. So, essentially, say, 10 hosts, with the same (2) system reporting in the files, so a... (0 Replies)
Discussion started by: jdubbz
0 Replies

6. UNIX for Advanced & Expert Users

Sendmail not showing recipients

I've figured out to do a mail merge with /usr/lib/sendmail which is extremely helpful as it is lightning fast compared to an Outlook mail merge which pretty much locks up my machine while it struggles to push out the emails. I figured out how to send html emails, with dynamic variables, and how... (8 Replies)
Discussion started by: MaindotC
8 Replies

7. Shell Programming and Scripting

Run multiple python programs sequentially.

I HAVE WRITTEN NINE PYTHON CODES TO PERFORM A TASK ........ I WISH TO RUN THEM SEQUENTIALLY. eg. code1__code2 >>>>>>>>code9.py TO GET DESIRED OUTPUT. PLS HELP ME WRITTING SHELL SCRIPT .. I HAVE TO DISTRIBUTE THESE CODE FOR BEING USED BY OTHERS. (2 Replies)
Discussion started by: upvan111
2 Replies

8. UNIX for Advanced & Expert Users

Multiple recipients with sendmail

Hi, I use the following to send a mail : sendmail -v someone@box.com < /appli/oracle/rap.txt Can I give several mail address for destination ? How ? For exemple : sendmail -v someone@box.com, someone2@box.com, someone3@box.com < /appli/oracle/rap.txt Thank you. (6 Replies)
Discussion started by: big123456
6 Replies

9. Shell Programming and Scripting

Shell script to run a python program on multiple entries in a file

Hello I am trying to run a python program using shell script, which takes a single argument from a file. This file has one entry per line : 1aaa 2bbb 3ccc 4ddd 5eee ... ... ... My shell script runs the program, only for the last entry : #!/bin/sh IFS=$'\n' for line in $(cat... (2 Replies)
Discussion started by: ad23
2 Replies

10. UNIX for Dummies Questions & Answers

using mailx with multiple recipients

I am trying to use a file containing email addresses in my mailx command like the following: SUBJECT="Kronos User Report" BODY="kronos.txt" MAILTO="kronosmail.txt" mailx -s "$SUBJECT" $MAILTO < $BODY This works fine for the body of the message but for the recipient it says: ... (6 Replies)
Discussion started by: sdhalepaska
6 Replies
Login or Register to Ask a Question