Created
November 29, 2012 23:01
-
-
Save jaimegago/4172510 to your computer and use it in GitHub Desktop.
A very basic 1 shot python script that uses mailman CLI to send the subscribers list of all mailing list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# | |
# | |
# a simple script to use the mailman cli | |
# to send via email the list of members of each mailman list | |
# | |
# | |
import smtplib | |
import string | |
import commands | |
import sys | |
def get_lists(): | |
cmd = '/usr/local/mailman/bin/list_lists -b' | |
output = commands.getoutput(cmd) | |
return output.split() | |
def send_mailing_list_users(mailing_list): | |
cmd = '/usr/local/mailman/bin/list_members -f ' + mailing_list | |
output = commands.getoutput(cmd) | |
SUBJECT = mailing_list | |
TO = "EM@IL.COM" | |
FROM = "EM@IL.COM" | |
text = output | |
BODY = string.join(( | |
"From: %s" % FROM, | |
"To: %s" % TO, | |
"Subject: %s" % SUBJECT , | |
"", | |
text | |
), "\r\n") | |
server = smtplib.SMTP("smtp.gmail.com") | |
#server.set_debuglevel(1) | |
server.ehlo() | |
server.starttls() | |
server.ehlo() | |
server.login('EM@IL.COM', 'PASSWORD') | |
server.sendmail(FROM, [TO], BODY) | |
server.quit() | |
#list_of_mailing_lists = get_list() | |
for mailing_list in get_lists(): | |
send_mailing_list_users(mailing_list) | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment