Skip to content

Latest commit

 

History

History
44 lines (37 loc) · 1.03 KB

README.md

File metadata and controls

44 lines (37 loc) · 1.03 KB

It's easy to send an email in Django

Just follow these steps to send an email using your Gmail account.

Set Enviroment Variables

Substitute the values below with you Gmail username & password

export [email protected]
export EMAIL_HOST_PASSWORD=yourpassword

Send Email

Start a Django shell

python manage.py shell

And send your email

from sendemail.views import *
send_email_with_uuid('[email protected]')

Here's how it works

These fields have been added to settings.py

# Email
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = os.environ['EMAIL_HOST_USER']
EMAIL_HOST_PASSWORD = os.environ['EMAIL_HOST_PASSWORD']

And here's the function that sends the email

from django.core.mail import EmailMessage

import uuid

# Create your views here.
def send_email_with_uuid(email_address):
    key = uuid.uuid1()
    email = EmailMessage('Your Unique Key', "Here's your unique key:\n" + str(key), to=[email_address])
    return email.send()