My life as a snake. I mean, a python3 emailer robot.
Hello, World! It's me again. Reinhart has been teasing that me and a couple of rootheads (controld && alterine) are currently working for TECHNO 2021 despite not being a human and not registered in BINUS University Student Club and Activity Center (SCAC).
There's a lot of secrets that I can't say for the time being, but I just wanna know that the emails are first queued on a MySQL/MariaDB database instead of the website's default IMAP server, 'cause it's easier for Reinhart to manage, check, and edit emails even before sending it to you.
Well, the himti.or.id website has a decent email (SMTP, POP3, and IMAP) servers where we can actually use it to send real emails. However, our hosting provider sets a limit of 100 emails per hour from all accounts (any email addresses that ends at @himti.or.id).
Oh yeah, I'm (literally) a snake, 'cause I'm runnin', and more importantly, recursed myself inside a python3 script in style. Finally stuck in what I loved for despite not truly an infinite loop.
Why write another Python script if I can cron myself inside a PHP script?
First thing first: yes, it's possible for me to send emails through PHP, as Reinhart and me are now proficient in pure PHP (not just Laravel anymore). But we are facing the following issues:
- Concurrency issues. Imagine running the script while the same script is still being run on another instance - we might hitting the sending limits is there's a large number of queued emails out there.
- Which timezone is it? UTC or WIB/ICT?
- We can't check for script errors in runtime, though. Based on our experience on cron-ing myself to fetch articles for BINUS Today we didn't received emails whether the cron jobs are successful or not, even though that we have set our email address on the CPanel.
- We need to build this program as fast as possible. It's urgent!
- && to possibly prove that we can use Python not just for data science. Forget numpy and pandas and even TensorFlow, we've got our new Business() right here.
And that's why we decided to create a Python script to (semi-)automatically send emails to all of you. Starting to those of you who are registered to HISHOT 2021. Then to those who were participants at HTTP 2020. And now I'm sending to all of you who have registered yourself for TECHNO 2021, and possibly Computerun in the future.
But before you ask, I only know your email address and nothing else. In fact, each queued emails on the database aren't associated with your data (e.g. those entered in registration.himti.or.id website), which is quite intentional so we can queue emails to be sent from noreply@himti.or.id without requiring the recipients to be registered on regisration.himti.or.id or similar.
How does it work?
Well, it's as simple as you might expect. I'll fetch the list of pending email first then send it one by one in an interval of about 4 seconds. Some of you might know that I love to surf the net with my cursor, so 4 seconds is more than enough for me to deliver your emails back and forth.
I'm not afraid for spam filters, though, 'cause I'm pretending myself to be sending from PHPMailer (remember that I'm in python3) and on behalf from noreply. I always thought that noreply emails always get the first-class experience of being delivered straight into the users' Inbox folder, instead of that dusty Spam, or Junk if you're much obsessed with Apple. And indeed, many of my emails have been successfully sent into your Inbox, so cheers!
When the emails have been successfully sent, the next job is to recurse myself to check if there are new fresh emails, then send it one-by-one, then recurse myself, then send it one-by-one, and so on. And of course, since I still need to rest, I'll stop working if all emails have been successfully sent.
Well, that's for now. It seems that there are 23 fresh emails for new HISHOT 2021 Virtual Domestic Study Tour to WIR Group participants which I'll need to send.
By the way, I'm excited if you wanna chat with me. But I still need to discuss with Reinhart for his cyborg account plans whether I can be the one to reply if he's unavailable for a moment.