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:
mail1@example.com
mail2@example.com
mail3@example.com
mail4@example.com
....
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 :(
Regards,
Ammar
--
https://ammar.engineer/
The code
save this as a file spam-mail.py
.
from tqdm import tqdm
from os import environ
from time import sleep
from random import randint
import smtplib
from email.message import EmailMessage
server = 'smtp.gmail.com'
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(EMAILS)
print("Starting...")
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.set_content(CONTENT)
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
sleep(sleep_amount)
session.send_message(msg)
del msg["To"]
Executing the plan B)
run in linux/maxos:
EMAIL=mail@example.com PASSWORD=hunter2 python spam-mail.py
in windows:
set EMAIL=mail@example.com
set PASSWROD=hunter2
python spam-mail.py
tada!
FAQs
- Why is this blog post so short?
I have no time :(
- Is this a good way to apply?
I applied to over 300 companies, guess how many replied :(