How I Automate Applying to Jobs (with Python)

Sending Emails the lazy way :)

Getting the emails

First one needs to get a list of emails. There are many tools, from the adobe experience to shady random websites. I prefer to use local linux tools so here we go:

pdftotext file.pdf - | grep -E '[-0-9a-zA-Z.+_]+@[-0-9a-zA-Z.+_]+\.[a-zA-Z]{2,4}'

In my case i had to take the first columm, so

pdftotext file.pdf - | grep -E '[-0-9a-zA-Z.+_]+@[-0-9a-zA-Z.+_]+\.[a-zA-Z]{2,4}' | awk '{print $1}'

Move this list to a txt file, in my case I called it emails.txt. This is how it looks like:

Your message

save your message as a text file, I use the following format, ans save to content.txt

I am writing to express my strong interest in getting a job :(




The code

save this as a file

from tqdm import tqdm
from os import environ
from time import sleep
from random import randint
import smtplib
from email.message import EmailMessage

server = ''
port = 587
user = environ.get('EMAIL')
password = environ.get('PASSWORD')

EMAILS_path = "emails.txt" # or any other path
CONTENT_path = "content.txt"
attachment1 = "<PATH>"
attachment2 = "<PATH>"
FROM_EMAIL = user # or '<XXXX>@<XXXXX>'

EMAILS = open(EMAILS_path).read().splitlines() 
CONTENT = open(CONTENT_path).read()

print("Found" , len(EMAILS), "emails!")

session = smtplib.SMTP(server, port = port)
session.starttls() # remove for outlook
session.login(user, password)

msg = EmailMessage()
msg["Subject"] = "<Subject>"
msg["From"] = FROM_EMAIL
msg.add_attachment(open(attachment1, "rb").read(), filename="attachment1",  maintype='application', subtype='pdf')
msg.add_attachment(open(attachment2, "rb").read(), filename="attachment2",  maintype='application', subtype='pdf')

# TODO: DNS validation

# Send to every email in the list
for i, recipient in enumerate(tqdm(EMAILS)):
    # sleep between 2 and 7 to avoid getting flagged as a bot
    sleep_amount = 2 + randint(0, 5)
    tqdm.write("{} Sending to {}... sleep: {}s".format(i, recipient, sleep_amount))
    msg["To"] = recipient
    del msg["To"]

Executing the plan B)

run in linux/maxos: PASSWORD=hunter2 python

in windows:

set PASSWROD=hunter2



  1. Why is this blog post so short?

I have no time :(

  1. Is this a good way to apply?

I applied to over 300 companies, guess how many replied :(