32 lines
815 B
Python
32 lines
815 B
Python
import requests
|
|
|
|
import personal_data.secrets as secrets
|
|
|
|
MAILGUN_API_ENDPOINT = 'https://api.mailgun.net/v3/{mailgun_domain}/messages'
|
|
|
|
FROM_MAIL_NAME = 'Personal Scrapers'
|
|
FROM_MAIL_USERNAME = 'scrapers'
|
|
|
|
|
|
def send_email(session: requests.Session, subject: str, text: str):
|
|
assert isinstance(session, requests.Session)
|
|
|
|
assert subject != ''
|
|
assert text != ''
|
|
|
|
data = {
|
|
'from': f'{FROM_MAIL_NAME} <{FROM_MAIL_USERNAME}@{secrets.MAILGUN_DOMAIN}>',
|
|
'to': [secrets.MAILGUN_RECIPIENT],
|
|
'subject': subject,
|
|
'text': text,
|
|
}
|
|
url = MAILGUN_API_ENDPOINT.format(mailgun_domain=secrets.MAILGUN_DOMAIN)
|
|
response = session.post(
|
|
url,
|
|
auth=('api', secrets.MAILGUN_API_KEY),
|
|
data=data,
|
|
)
|
|
response.raise_for_status()
|
|
return response
|
|
|