Email Client Implementation
Now let's actually implement our email client in the project.
Setting up URL Patterns
Make sure you've added a URL pattern for your new endpoint in your app's urls.py
file.
Just to be clear, in our example, we created a email_client
app in our Django project. We need to create a urls.py
file in the app directory (if it's not created already), and add that above URL path.
If it's not already, make sure your app's URLs are included in the project's urls.py
.
This urls.py
file should be sitting in the same directory as settings.py
.
Setting up Views
Last thing is to add our view function to actually send the email.
Every time this endpoint is hit, an email will be sent to the specified recipient. Of course, we could modify the view function with lots of improvements.
- If this scenario was a user submitting a contact form, the view function could be changed to send a confirmation that the email was received to the user's email, and the form contents could be emailed to you.
- Create a custom email template. This is something usually limited when using the free tier of other email clients.
- We didn't utilize the
models.py
file. We could adjust the view function to also save copies in the database.
Part of: Django Email Client