Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

sending email with django

from django.core.mail import send_mail
class UserList(generics.ListCreateAPIView):
    queryset = User.objects.all()
    serializer_class = UserSerializer
    def perform_create(self, serializer):
        created_object = serializer.save()
        send_mail('Subject here','Here is the message.','from@example.com', 
            [created_object.email],  fail_silently=False,)
Comment

Django email

from django.core.mail import EmailMultiAlternatives
from django.template.loader import get_template
from django.template import Context

plaintext = get_template('email.txt')
htmly     = get_template('email.html')

d = Context({ 'username': username })

subject, from_email, to = 'hello', 'from@example.com', 'to@example.com'
text_content = plaintext.render(d)
html_content = htmly.render(d)
msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
msg.attach_alternative(html_content, "text/html")
msg.send()
Comment

PREVIOUS NEXT
Code Example
Python :: python list of all characters 
Python :: python defaultdict example 
Python :: python close browser 
Python :: how to update the kali linux os from python2 to python3 
Python :: remove alphabetic characters python 
Python :: python get current month 
Python :: encrypt string python 
Python :: python style console output 
Python :: how to make a randomized pasword genirator in python 
Python :: create a df in pandas 
Python :: python find specific file in directory 
Python :: python timestamp 
Python :: python new line command 
Python :: exec to return a value python 
Python :: tofixed in python 
Python :: python extract text from image 
Python :: finding the index of an element in a pandas df 
Python :: python process memory usage 
Python :: pandas rename multiple columns 
Python :: django connection cursor 
Python :: timeit jupyter 
Python :: how to run python file from cmd in dockerfile 
Python :: python import multiple csv 
Python :: python read from stdin 
Python :: create 3x3 numpy array 
Python :: python absolute value 
Python :: Math Module log() Function in python 
Python :: describe function in pandas 
Python :: import django-on-heroku 
Python :: python get memory address of variable 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =