FORM 'CONTACT US'

25 views
Skip to first unread message

Matteo Fiameni

unread,
Mar 19, 2018, 6:18:37 AM3/19/18
to django CMS users
Good morning! I created a form with the relevant contact fields and a submit button. Now, how can I get an email sent to my gmail address? Can I do everything from the toolbar? Ty

Maurício Mendes

unread,
Apr 6, 2020, 4:32:01 PM4/6/20
to django CMS users
Hello,

1) You need to add settings on settings.py
# EMAIL SENDER
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'YourA...@gmail.com'
EMAIL_HOST_PASSWORD = 'YourPassword'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

2) you have to create a view to send it

from django.core.mail import send_mail

def messageform(request):
    contact_name = request.GET.get('contact_name')
    contact_email = request.GET.get('contact_email')
    contact_message = request.GET.get('contact_message')

    print(contact_name)
    print(contact_email)
    print(contact_message)

    res = send_mail('Contact', contact_name + ' ' + contact_email + ' ' + contact_message, contact_email, ['YourA...@gmail.com.br'], fail_silently=True)

    if res:
        messages.success(request, 'Sucess')
    else:
        messages.success(request, 'Error!')

    return HttpResponseRedirect('/')  # render(request, 'main/MessageSend.html', )


I Hope that helps.
Reply all
Reply to author
Forward
0 new messages