Created
May 28, 2024 16:38
-
-
Save jklymak/13e2f387732da7c553f43079537b8ed7 to your computer and use it in GitHub Desktop.
Write to request references from yaml list of referees
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import smtplib | |
import yaml | |
from email.message import EmailMessage | |
from email.utils import make_msgid | |
from email.mime.base import MIMEBase | |
from email import encoders | |
from email.mime.multipart import MIMEMultipart | |
from email.mime.text import MIMEText | |
from email.mime.application import MIMEApplication | |
smtp_server = 'smtp.local.com' | |
smtp_port = 587 | |
smtp_username = '[email protected]' | |
smtp_password = 'xxxx' | |
""" | |
Yaml is something like: | |
Joan Smith: | |
- Jones: [email protected] | |
- Piper: [email protected] | |
Fred Cohen: | |
- Frances: [email protected] | |
- Piper: [email protected] | |
""" | |
with open('References.yaml') as fin: | |
references = yaml.safe_load(fin) | |
print(references) | |
for app in references: | |
print(app) | |
for ref in references[app]: | |
for reff in ref: | |
print(reff) | |
print(ref[reff]) | |
reference = reff | |
email = ref[reff] | |
applicant = app | |
from_email = '[email protected]' | |
to_email = email | |
subject = f'Subject: PDF reference for {applicant}' | |
body = f""" | |
Dear Dr. {reference} | |
We received an application from {applicant} for a postdoctoral fellowship on "Ocean sub-mesoscales using in-situ data, satellites, and simulations" with our group at UVic and DFO. The job advertisement is attached below. They are on our long list of potential applicants and we were wondering if you had a few minutes to give us an idea of their suitability for the position. We are particularly interested in the level of independence and originality they showed in their research with you, and if you feel they would be successful in the role. We appreciate that you probably have lots of other commitments, so an informal email in response is fine, or we are happy to have a quick call if that is easier. | |
Thanks, | |
Jody Klymak, | |
""" | |
msg = MIMEMultipart() | |
msg['From'] = from_email | |
msg['To'] = to_email | |
msg['Subject'] = subject | |
msg['Cc'] = '[email protected], [email protected]' | |
msg.attach(MIMEText(body, 'plain')) | |
pdf_filename = 'PDF_CSA_2024_Ad.pdf' | |
with open(pdf_filename, 'rb') as f: | |
pdf_attachment = MIMEApplication(f.read(), _subtype='pdf') | |
pdf_attachment.add_header('Content-Disposition', 'attachment', filename=pdf_filename) | |
msg.attach(pdf_attachment) | |
try: | |
with smtplib.SMTP(smtp_server, smtp_port) as server: | |
server.starttls() # Upgrade the connection to secure | |
server.login(smtp_username, smtp_password) | |
server.sendmail(from_email, to_email, msg.as_string()) | |
print('Email sent successfully') | |
except Exception as e: | |
print(f'Failed to send email: {e}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment