Last active
March 16, 2019 00:41
-
-
Save syedsaqibali/9066627 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.mail import send_mail | |
import os | |
def sendMyAppEmail(toList, template, toType=None, subject="", templateDict={}): | |
# Load the image you want to send at bytes | |
img_data = open(os.path.join(settings.MEDIA_ROOT, 'bumblebee.jpeg'), 'rb').read() | |
# Create a "related" message container that will hold the HTML | |
# message and the image | |
msg = MIMEMultipart(_subtype='related') | |
# Create the body with HTML. Note that the image, since it is inline, is | |
# referenced with the URL cid:myimage... you should take care to make | |
# "myimage" unique | |
body = MIMEText('<p>Hello <img src="cid:myimage" /></p>', _subtype='html') | |
msg.attach(body) | |
# Now create the MIME container for the image | |
img = MIMEImage(img_data, 'jpeg') | |
img.add_header('Content-Id', '<myimage>') # angle brackets are important | |
msg.attach(img) | |
send_mail( | |
subject=subject, | |
message=msg.as_string(), | |
from_email=settings.DEFAULT_FROM_EMAIL, | |
recipient_list=toList, | |
fail_silently=False, | |
) | |
sendMyAppEmail(["[email protected]"], None, toType=None, subject="Hello World3", templateDict={}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
How do I add context to my template if I need to?