Hallo Community,
ein kleines Mass-Mailer Python Skript habe ich geschrieben.
Hier kurz die usage dazu:
Usage: massmailer.py -s "Your Name" -i
Der Betreff ist hierbei der Parameter -s
Unsere eigene Email von der wir senden (Kann auch gefälscht werden) ist der Parameter -i
Der Parameter -c ist der Inhalt bzw. Text den wir per Email versenden möchten
Parameter -m ist eine Auflistung von Emails als Textdokument zu denen gesendet wird
Parameter -f ist optional und kann eine Datei als Anhang für die Mail nutzen
#!/usr/bin/python # Author: MR_NOP from email.mime.multipart import MIMEMultipart from email.mime.application import MIMEApplication from email.mime.text import MIMEText from socket import * import optparse import smtplib import sys def Intro(): print 'Python Mass-Mailer @ MR_NOP [Version 1.0.0.0]\n' def sendMail(s, subject, from_mail, content, mail, note=None, note_name=None, format=None): msg = MIMEMultipart() msg['Subject'] = subject msg['From'] = from_mail msg['To'] = mail text = MIMEText(content) msg.attach(text) if not (note == None): att = open(note_name, 'rb') temp = MIMEApplication(att.read(), _subtype=format) temp.add_header('Content-Disposition','attachment',filename=note_name) att.close() msg.attach(temp) s.sendmail(from_mail.split('@')[0] + ' <' + from_mail + '>', mail, msg.as_string()) def massMail(subject, from_mail, content, emails, note=None): note = '' if (note == None) else note if not (note == None): try: format = note.split('.')[1] except: pass Intro() print 'Subject: ' + subject print 'From : ' + from_mail print 'Content: ' + content print 'Emails : ' + emails print 'Note : ' + note + '\n' if not (note == ''): try: n = open(note, 'rb') except: print '[-] Cannot find ' + note + ' file' + '\n' sys.exit(0) try: c = open(content) con = c.read() c.close() except: print '[-] Cannot find ' + content + ' file' + '\n' sys.exit(0) try: e = open(emails) except: print '[-] Cannot find ' + emails + ' file' + '\n' sys.exit(0) try: import smtp_config svr = smtp_config.address port = smtp_config.port tls = smtp_config.tls username = smtp_config.username password = smtp_config.password except: try: print '[*] Config file was not found!' svr = raw_input('SMTP-Server> ') port = raw_input('SMTP-Port> ') tls = raw_input('Using TLS? (yes,no)> ') username = raw_input('Username> ') password = raw_input('Password> ') print '[*] Create config file...' config_file = open('smtp_config.py', 'w') config_file.write('address=\''+svr+'\'\n') config_file.write('port=\''+port+'\'\n') config_file.write('tls=\''+tls+'\'\n') config_file.write('username=\''+username+'\'\n') config_file.write('password=\''+password+'\'') config_file.close() print '[+] Done.' except: print '[-] SMTP config error, something went wrong!' + '\n' sys.exit(0) try: s = smtplib.SMTP(svr, int(port)) if (tls == 'y') | (tls == 'yes'): s.starttls() s.login(username, password) except: print '[-] SMTP config error, something went wrong!' + '\n' sys.exit(0) counter = 0 if (note == ''): for mail in e.readlines(): counter = counter + 1 sys.stdout.write('\rSend: '+str(counter)+' - '+mail) sys.stdout.flush() sendMail(s, subject, from_mail, con, mail) else: for mail in e.readlines(): counter = counter + 1 sys.stdout.write('\rSend: '+str(counter)+' - '+mail) sys.stdout.flush() sendMail(s, subject, from_mail, con, mail, n, note, format) def main(): parser = optparse.OptionParser('Usage: %s -s <subject> -i <from> -c <content> -m <emails> -f <file>' % sys.argv[0].split('/')[-1]) parser.add_option('-s', dest='subject', type='string', help='specify subject') parser.add_option('-i', dest='from_mail', type='string', help='specify email from of sender') parser.add_option('-c', dest='content', type='string', help='specify mail content from text file') parser.add_option('-m', dest='emails', type='string', help='specify emails from text file') parser.add_option('-f', dest='file', type='string', help='specify email note') (options, args) = parser.parse_args() subject = options.subject from_mail = options.from_mail content = options.content emails = options.emails note = options.file if (subject == None) | (from_mail == None) | (content == None) | (emails == None): print parser.usage + '\n' sys.exit(0) if (note == None): massMail(subject, from_mail, content, emails) else: massMail(subject, from_mail, content, emails, note=note) if __name__ == '__main__': main()