commiting
This commit is contained in:
57
all_paw_care/forms/meetgreetnotification.py
Normal file
57
all_paw_care/forms/meetgreetnotification.py
Normal file
@@ -0,0 +1,57 @@
|
||||
from config import Config
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
# TODO replace self.smtp_url and self.email_user with Config values
|
||||
|
||||
class MeetGreetNotification(object):
|
||||
def __init__(self, config: str):
|
||||
self.smtp_url =
|
||||
self.email_user =
|
||||
|
||||
def __get_smtp_client(self):
|
||||
from smtplib import SMTP_SSL
|
||||
|
||||
smtp_client = SMTP_SSL(host=self.smtp_url)
|
||||
smtp_client.login(self.email_user,self.c['fastmail-smtp']['pass'])
|
||||
|
||||
return smtp_client
|
||||
|
||||
def send(self, name: str, address: str, greet_time: datetime, notes: str = None):
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.text import MIMEText
|
||||
|
||||
|
||||
subject = "Meet & greet request: {}".format(name)
|
||||
email = MIMEMultipart()
|
||||
email['Subject'] = subject
|
||||
email['From'] = self.email_user
|
||||
email['To'] = self.email_user
|
||||
|
||||
content = '''
|
||||
<table>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<td>{}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Address</th>
|
||||
<td>{}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Datetime</th>
|
||||
<td>{}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Notes</th>
|
||||
<td>{}</td>
|
||||
</tr>
|
||||
</table>
|
||||
'''.format(name,address,greet_time,notes)
|
||||
|
||||
email_content = MIMEMultipart('alternative')
|
||||
email_content.attach(MIMEText(content, 'html'))
|
||||
email.attach(email_content)
|
||||
|
||||
with self.__get_smtp_client() as c:
|
||||
c.sendmail(self.email_user,self.email_user,email.as_string())
|
||||
Reference in New Issue
Block a user