Last active
October 27, 2020 18:32
-
-
Save jeansymolanza/3054e351981e996b023669288cfb8762 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/python3 | |
import smtplib | |
from email.mime.text import MIMEText | |
from email.mime.multipart import MIMEMultipart | |
from email.mime.base import MIMEBase | |
from email import encoders | |
import os.path | |
import csv | |
from random import randint | |
from time import sleep | |
def send_email(email_recipient, | |
email_subject, | |
email_message, | |
attachment_location=''): | |
email_mime_sender = 'John Doe <john_doe@email.com>' | |
email_sender = 'john_doe@email.com@email.com' | |
email_password = 'johndoe123' | |
msg = MIMEMultipart() | |
msg['From'] = email_mime_sender | |
msg['To'] = email_recipient | |
msg['Subject'] = email_subject | |
msg.attach(MIMEText(email_message, 'plain')) | |
if attachment_location != '': | |
filename = os.path.basename(attachment_location) | |
attachment = open(attachment_location, "rb") | |
part = MIMEBase('application', 'octet-stream') | |
part.set_payload(attachment.read()) | |
encoders.encode_base64(part) | |
part.add_header('Content-Disposition', | |
"attachment; filename= %s" % filename) | |
msg.attach(part) | |
try: | |
server = smtplib.SMTP('smtp.email.com', 999) | |
server.ehlo() | |
server.starttls() | |
server.login(email_sender, email_password) | |
text = msg.as_string() | |
server.sendmail(email_sender, email_recipient, text) | |
print('Email sent to %s' % email_recipient) | |
server.quit() | |
except: | |
print("SMTP server connection error") | |
return True | |
def main(): | |
file = 'job-app-template.csv' | |
with open(file, "rb") as f: | |
next(f) | |
for line in f: | |
line = line.replace("\n", "") | |
line = line.replace("\r", "") | |
split_line = line.split(",") | |
email_subject = 'Full-Stack Software Developer Intereted in Joining ' + split_line[ | |
0] | |
raw_email_message = [ | |
'Hi ' + split_line[2] + ',', | |
'I hope that this finds you well.', | |
'I am writing this email to express my interest in joining your firm as a Full-Stack Software Developer. Please find attached my CV and covering letter. Feel free to contact me if you have any further questions. I look forward to hearing from you.', | |
'Thank you for your time and consideration.', 'Kind regards,', | |
'John Doe' | |
] | |
email_message = '\n\n'.join(raw_email_message) | |
attachment_location = 'JohnDoeCV.pdf' | |
send_email(split_line[1], email_subject, email_message, | |
attachment_location) | |
sleep(randint(1, 3)) | |
main() |
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
company | key_contact | ||
---|---|---|---|
Cool Startup | info@coolstartup.com | Max |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment