First commit
This commit is contained in:
parent
c8624114e6
commit
887bc5e222
38
README.md
38
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
|
||||
})
|
||||
|
23
sendwave.py
Normal file
23
sendwave.py
Normal file
@ -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()
|
Loading…
Reference in New Issue
Block a user