Authentication system in the forum application #4: Configuration in mailtrap.io and Send verification email
utopian-io·@duski.harahap·
0.000 HBDAuthentication system in the forum application #4: Configuration in mailtrap.io and Send verification email
#### Repository https://github.com/python #### What Will I Learn? - Configuration in mailtrap.io - Send verification email #### Requirements - Basic Python - Install Python 3 - Install Django #### Resources - Python - https://www.python.org/ - Django- https://www.djangoproject.com/ - Bootstrap 4 - https://getbootstrap.com/docs/4.0/getting-started/introduction/ - Mailtrap.io https://mailtrap.io #### Difficulty Basic ### Tutorial Content This tutorial is a continuation of the previous tutorial about verifying users with email. Because we use email verification. Of course, we need some configuration because we run the application through our local server. In this tutorial we will learn how to implement our e-mail with the help of new tools, that is **mailtrap.io**. With this tool, we can send emails from our local server. For those of you who are just following this tutorial, I suggest you follow the previous tutorials. ### Use mailtrap.io We will use an additional tool in the Django application that we created. this tool is mailtrap.io. the use of these tools to help us for development needs when sending emails. Of course, we need a test or check before we send the email feature in the *production or real project* stage. So **mailtrap.io** is very useful for those of you who want to test or see emails that are sent during the development process. to start using it we can create an account first. - **Start using mailtrap.io** The first thing we will do is create an account that we will use to be able to access the dashboard in **mailtrap.io.** to create an account in **mailtrap.io** you can use your **GitHub** account or your **Gmail** account, as I did in the picture below:  **mailtrap.io** is a paid tool but for the sake of simple testing send an email to mailtrap.io that has provided it for free. After we register and log in we will be given access to the dashboard page and on the dashboard, we have an inbox, now the inbox provided for free is a **demo inbox**. <br> - **Configuration in mailtrap.io** We can click to enter the **demo inbox**, now here is an important part of its use, for more details we can see in the picture that I present below: .gif) There are several configurations that are offered by mailtrap.io, what we will use is the Python language with the Django framework, so we can select the configuration. for more details, we can see in the following picture.  As we saw in the picture above to configure it in mailtrap.io we have to add the following code in **apps/settings.py** ``` EMAIL_HOST = 'smtp.mailtrap.io' EMAIL_HOST_USER = '9650522bb15611' EMAIL_HOST_PASSWORD = '9dfe19de3b6fc4' EMAIL_PORT = '2525' ```  Well, now we have finished configuring in mailtrap.io the next step is to create an email activation in the application that we made. ### Send email activation In this section we will continue to create activation emails that we have made in the previous [tutorial](https://steemit.com/utopian-io/@duski.harahap/authentication-system-in-the-forum-application-3-generate-token-and-email-configuration), In the previous tutorial, we have defined our email template, namely **activation_email.html**. Well, in this section we will make the template, here is the template that we will create: - **Create an email template** We will start creating email templates, in this template I have passed a number of variables to render in the template, we can see in the code below to see what variables I passed in this template:  - to use the ```render_to_string ()``` function we must import it first like this ```from django.template.loader import render_to_string```. - to use the ```force_bytes ()``` function we can import it first like the following ```from django.utils.encoding import force_bytes``` and the following is a template that we will render in an email: **activation_email.html** ``` {% autoescape off %} Hi, {{user.username}} Please click the link below, to activate your account http://{{domain}}{% url 'activate' uidb64=uid token=token %} {% endautoescape %} ``` Well in this template I will render a link for activation ```http://{{domain}}{% url 'activate' uidb64=uid token=token %}```, the link consists of domains, uids and tokens that have been generated. We haven't created the route yet. we will make it in the next section. - **Make routing for link activation** We have passed a link in the activation email now we will create the link. I will create a new routing and accept some parameters, namely ***uid and token***. For more details, we can in the code below: **account/urls.py** ``` from django.urls import path from . import views urlpatterns = [ path('signup/', views.SignUp, name='signup'), path('password_change/', views.ChangePassword, name='change-password'), path('activate/<uidb64>/<token>', views.Activate, name='activate') // path for activation ] ``` - we have created a new path that is ```path('activate/<uidb64>/<token>', views.Activate, name='activate')```. In this routing I will accept the ```<uidb64>``` and ```<token>``` and define the Activate function in the view class ```views.Activate``` and also give an alias ```name='activate'``` as we have ***rendered*** it in template. - And next I will make the Activate function in the view class, this function will only return so that no error occurs. ``` def Activate(request): return ``` If all the steps above have been completed we can do an experiment like the demonstration that I have made below: .gif)  We can see in the picture above we have successfully sent an email by sending a verification link to the email we sent. this means our assignment has been completed in this tutorial. In the next tutorial, we will activate the user via the clicked link. ### Curriculum - **Forum app** [django#1](https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-1-init-projects-and-dependencies-and-database-schema-1551711163679), [django#2](https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-2-template-system-and-class-based-view-implementation-1552057536737), [django#3](https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-3-base-template-login-and-register-system-1552311993977), [django#4](https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-4-admin-dashboard-ang-setting-redirect), [django#5](https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-5-slug-concept-and-generated-slug-and-use-forms-generic-view), [django#6](https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-6-crud-system-and-url-protection-redirect-system), [django#7](https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-7-unique-slug-and-manage-modules-in-admin-dashboard-1553268749861), [django#8](https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-8-display-forum-data-and-create-and-implement-list-view-1553525769014), [django#8](https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-8-display-forum-data-and-create-and-implement-list-view-1553525769014), [django#9](https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-9-single-page-for-forums-passing-params-in-routing-and-make-time-humanize-1553788983186), [django#10](https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-10-detail-page-for-forums-use-slug-as-the-parameter-url-and-implement-getcontextdata), [django#11](https://steemit.com/utopian-io/@duski.harahap/create-a-forum-application-using-django-11-url-behavior-and-update-view-and-edit-menu-1554268753908) #### Proof of work done https://github.com/milleaduski/forums-django
👍 pgshow, jadabug, celmor, imisstheoldkanye, eforucom, accelerator, ezravandi, zugs, reazuliqbal, minminlou, hdu, graceb9l73, phelrenew, fontetersti, roringeotur, liaguelati, natalieqz01, anna4dm, pataty69, faireasadown, sesmocentpi, jessicaolmuf, avaa5pb3hall, durchmanfaimet, morganit, elizabethg4, rachelcku, katherineye, emma3l0, ciedustsouthti, biominesfi, mcadevinar, micaelacf, tatylayla, bhaski, mightypanda, karlosantonio, adriellylayla, vivapizza, renatomacedo, edjesus, pinguimpaulo, sadino, cetandradefor, bolachasmonster, agostinhochiau, rafaelmonteiro, laurasoares, newstrikex, road2horizon, serialfiller, amosbastian, tobias-g, viperblckz, jaff8, rufans, helo, asaj, fego, bestofph, buckydurddle, ulockblock, jinger, kendallron, pinas, mirkosche, codingdefined, espoem, ascorphat, mops2e, aleister, shammi, veritasvav, dedicatedguy, portugalcoin, elena-singer, mcfarhat, wikita, penguinpablo, cryptonized, steemitri, luc.real, tbtek, haiyangdeperci, indayclara, filipino, chinchilla, misia1979, hozn4ukhlytriwc, topeng, loshcat, greenorange, bowess, ydavgonzalez, miniature-tiger, midun, camillesteemer, tensor, steem-ua, sargoon, yorvensito, utopian-io, tombstone, jga, cryptouno, dicetime,