Created
November 8, 2012 15:06
-
-
Save mapio/4039338 to your computer and use it in GitHub Desktop.
Mail merge in Python per mandare username e password
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
PASSWORD [email protected] |
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
from email.mime.multipart import MIMEMultipart | |
from email.mime.text import MIMEText | |
from smtplib import SMTP | |
from time import sleep | |
text = open( 'message.txt', 'r' ).read() | |
html = open( 'message.html', 'r' ).read() | |
smtp = SMTP( 'smtp.di.unimi.it' ) | |
for n, code_you in enumerate( open( 'codici.txt', 'r' ), start = 1 ): | |
code, you = code_you.split( '\t' ) | |
you = you.strip() | |
msg = MIMEMultipart( 'alternative' ) | |
msg[ 'Subject' ] = 'Codice per la registrazione a Campus Party' | |
msg[ 'From' ] = 'Massimo Santini <[email protected]>' | |
me = msg[ 'Reply-To' ] = '[email protected]' | |
msg[ 'To' ] = you | |
msg.attach( MIMEText( text.format( code, you ), 'plain' ) ) | |
msg.attach( MIMEText( html.format( code, you ), 'html', 'iso-8859-1' ) ) | |
smtp.sendmail( me, you, msg.as_string() ) | |
print '{0}\t{1}'.format( n, you ) | |
sleep( 1 ) | |
smtp.quit() |
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
<html lang="en"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8559-1"> | |
<title>Codice Campus Party</title> | |
<style type="text/css">body {{font-family: Arial, Helvetica, sans-serif;}} p {{ padding-bottom: 1em }}</style> | |
</head> | |
<body> | |
<p>Caro studente, <br/> | |
ti anticipo il codice per registrati sul sito di Campus Party Ë <strong>{0}</strong> | |
(va usato assieme all'indirizzo email <strong>{1}</strong> a cui hai ricevuto questa comunicazione).</p> | |
<p>Massimo Santini</p> | |
<p>PS<br/> | |
A breve dovresti ricevere anche una mail dall'organizzazione dell'evento.</p> | |
</body> | |
</html> |
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
Caro studente, ti anticipo il codice per registrati sul sito di Campus Party è {0} | |
(va usato assieme all'indirizzo email {1} a cui ricevi questa comunicazione). | |
Massimo Santini | |
PS | |
A breve dovresti ricevere anche una mail dall'organizzazione dell'evento. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment