Skip to content

aergener/DjangoEmail

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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()

About

How to send an email from Gmail account using Django

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages