59 lines
1.7 KiB
Python
59 lines
1.7 KiB
Python
from datetime import datetime
|
|
|
|
class MeetGreetNotification(object):
|
|
def __init__(self, config: str):
|
|
from configparser import ConfigParser
|
|
|
|
self.c = ConfigParser()
|
|
self.c.read(config)
|
|
|
|
self.smtp_url = self.c['fastmail-smtp']['url']
|
|
self.email_user = self.c['fastmail-smtp']['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())
|