With a basic pdf export available, it’s time to look at emailing the grocery list. When I add accounts, I want to give the user the option to do a one-click email to their inbox, so that they can easily access the grocery list outside of the app. In the meantime, I want to be able to allow the user to input an email address of their choice, and have the app send to the given email.
First, I created a test case, just to make sure I could actually send emails. I created a new gmail account for the app and added the email and password to my environmental variables. Then I imported flask_email
and set up a new email object for my app:
Note that I still only have one blueprint here. That’s going to have to change soon, I think. Things are getting a bit unweildy.
Then I added a new email route to my routes.py
folder and a placeholder mailing function in utils.py
, which doesn’t do anything but send a test email to myself.
(That’s my email address, by the way, in case you didn’t know. Feel free to contact me!)
Finally, I added a new button and, yes, a new modal to my list page. I’ve been thinking about the modals, and wondering if there might be a way to combine them into a single modal div component, and have dynamic information display. Something to consider for later. But for now, my copy/paste of the modal template continues.
I then added a button to email right next to the print button, in what’s becoming a toolbar of sorts:
I then sent a test email, and am pleased to report that it is working:
With the proof of concept up and running, it was time to make the email actually have important information. First, I created a new form in my forms.py
folder to take in the email address:
I added this form into my main list route and inserted it into my template on the modal I’d already made:
This created a nice looking modal:
Then, it was time to create the actual body of the email. I created a function in my utils.py
file that took in all of the relevant information from the list page, and produced a simply-formatted email. Because this is an email and therefore paper resources wouldn’t be an issue, I didn’t bother including as much customization, instead providing the list items (noting if they’re checked or not), the recipe names, and the links to the recipes. I tried to get a little more use out of f-strings in this process, and I’m reasonably pleased with how it turned out.
I gave it another test with the new email, and I’m pleased to report that everything seems to be working just fine:
And that’s about it for today! This was honestly much easier than I thought it would be; the whole process was fairly straightforward and I’m reasonably pleased with the result. Moving through the list quickly now; almost time for the last big feature: adding users. But a few more things to touch up on first.
Next Steps:
- text messaging (optional, need to investigate if it will cost money)
- some refactoring to prepare for adding users