'Dynamically Sending Email
I have email verification working in Django, it sucessfully sends an email to inbox when I click the submit button at the bottom of the signup page, but the only problem is that it does not yet have the function where it sends an email to the address of the user who just signed up, instead, it only sends the email to the email address hard coded in the views .py file .
Signup page: [![Signup page][1]][1]
views.py
from django.core.mail import EmailMessage
email = EmailMessage(
'Test', #email subject
'Hello,'
' This is the Robo Depot team. We wanted to let you know your
account is confirmed.'
' Thank You for joining the Robo Depot userbase.', #email body
'*********', #not sure what this does
['******', '******',
'***********'], #recipients
reply_to=['[email protected]'],
headers={'Message-ID': 'foo'},
)
email.send(fail_silently=False)
Settings.py
# Email
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_USE_TLS = True
EMAIL_USE_SSL = False
EMAIL_PORT = 587
EMAIL_HOST_USER = '**********'
EMAIL_HOST_PASSWORD = '*****'
register.html
<button id="signup-btn" type="submit" class="mt-3 btn btn-
primary" EmailMessage/cart/view.py">
Submit
</button>
I don't even know where to begin here. I think I need a get function to pull the value from the email address form field, but I have no clue how I would even get that. Anyone have any idea?
Solution 1:[1]
Where is the form data sent to?
that would be the action attribute in the <form> element.
say it's /api/register
you can set up a handler there to get the email address from the form and then call the emailing function with the address as a parameter.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Yarin_007 |
