diff --git a/README.md b/README.md index 029187d..4317ab3 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,38 @@ -# sendwave +# SendWave + Python Script for sending an emails. + +You need a `template library` to create an email with `html`. + +## Usage + +Here is the usage example with mako template: + + from mako.template import Template + + verification_url = "https://example.com/verification?token=xxxxxx" + + text = f"Please visit this link to complete the registration: {verification_url}" + html = Template(your_template).render( + link = verification_url + ) + +and here for send the email: + + import sendwave + + sendwave.smtp({ + "login" : { + "email" : "your_email@mail.com", + "password" : "your_password" + }, + "server" : { + "host" : 'smtp.mail.com', + "port" : 587 + }, + "subject" : "Your subject", + "from" : "your_email@mail.com", + "to" : "example@mail.com", + "text" : text, + "html" : html + }) diff --git a/sendwave.py b/sendwave.py new file mode 100644 index 0000000..452424e --- /dev/null +++ b/sendwave.py @@ -0,0 +1,23 @@ +from email.mime.multipart import MIMEMultipart +from email.mime.text import MIMEText +import smtplib + +def smtp(config): + + msg = MIMEMultipart('alternative') + msg['Subject' ] = config['subject' ] + msg['From' ] = config['from' ] + msg['To' ] = config['to' ] + + part1 = MIMEText(config['text'], 'plain') + part2 = MIMEText(config['html'], 'html' ) + + msg.attach(part1) + msg.attach(part2) + + smtp_server = smtplib.SMTP(config['server']['host'], config['server']['port']) + smtp_server.ehlo() + smtp_server.starttls() + smtp_server.login( config['login']['email'], config['login']['password'] ) + smtp_server.sendmail('&&&&&&', config['to'], msg.as_string() ) + smtp_server.quit()