Skip to content

Commit

Permalink
Changes to support embedded image.
Browse files Browse the repository at this point in the history
  • Loading branch information
sumathi.thirumani committed Jun 26, 2024
1 parent 19b454a commit c9e60a8
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ export const ContactApplicant = ({
let data = {
templateid: currentTemplate ? templates[currentTemplate as keyof typeof templates].templateid : null,
correspondencemessagejson: JSON.stringify({
"emailhtml": editorValue,
"emailhtml": emailContent,
"id": approvedForm?.cfrfeeid,
"type": type
}),
Expand Down
26 changes: 11 additions & 15 deletions request-management-api/request_api/services/email/senderservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
import json
from request_api.services.external.storageservice import storageservice
from request_api.models.default_method_result import DefaultMethodResult

from request_api.services.email.templates.embeddedimagehandler import embeddedimagehandler
import base64

MAIL_SERVER_SMTP = os.getenv('EMAIL_SERVER_SMTP')
MAIL_SERVER_SMTP_PORT = os.getenv('EMAIL_SERVER_SMTP_PORT')
Expand All @@ -41,18 +42,14 @@ def send(self, subject, content, _messageattachmentlist, emails):
logging.debug("Begin: Send email for request ")
content = content.replace('src=\\\"', 'src="')
content = content.replace('\\\">','">')
msg = MIMEMultipart('alternative')
msg = MIMEMultipart('related')
msg['From'] = MAIL_FROM_ADDRESS
msg['To'] = ",".join(emails)
msg['Subject'] = subject
part = MIMEText("""<html>
<body>
<img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBwgHBgkIBwgKCgkLDRYPDQwMDRsUFRAWIB0iIiAdHx8kKDQsJCYxJx8fLT0tMTU3Ojo6Iys/RD84QzQ5OjcBCgoKDQwNGg8PGjclHyU3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3N//AABEIAJQA+QMBIgACEQEDEQH/xAAbAAEAAgMBAQAAAAAAAAAAAAAABQ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I3Pe4NY0EknkAqlrnUMtNp6KKzZdcrs4U1CORy7Yv8gBvleGs6+W63mi0lb5OF0/6e4StP6qnad2n+bl6ZXjpaIak1VV6idk0FvDqC3MI2OMccn1936oLLpKxQabsNJa6fB7pmZHgY7yQ7ud8yphYGVlAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQFg8kRBxxlwnj01rvUTS38pPqpaYSkfBGwlrQB02GfUldQ03bqa02WhoaJnBBDAwNB5nbmfNEVEoiIoCIiAiIgIiICIiAiIgIiICIiAiIgIiICIiD/9k=" alt="Logo" style="max-width: 100; height: 100;">
</body>
</html>""", "html")
formattedContent, embeddedImages = embeddedimagehandler().formatembeddedimage(content)
part = MIMEText(formattedContent, "html")
msg.attach(part)
# Add Attachment and Set mail headers
"""
#Add Attachment and Set mail headers
for attachment in _messageattachmentlist:
file = storageservice().download(attachment['url'])
part = MIMEBase("application", "octet-stream")
Expand All @@ -63,13 +60,12 @@ def send(self, subject, content, _messageattachmentlist, emails):
"attachment", filename= attachment.get('filename')
)
msg.attach(part)
for embeddedImage in embeddedImages:
msgImg = MIMEImage(embeddedImage['bytes'], embeddedImage['type'])
msgImg.add_header('Content-ID', embeddedImage['cid'])
msgImg.add_header('Content-Disposition', 'inline', filename=embeddedImage['cid']+'.'+embeddedImage['type'])
msg.attach(msgImg)

img = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBwgHBgkIBwgKCgkLDRYPDQwMDRsUFRAWIB0iIiAdHx8kKDQsJCYxJx8fLT0tMTU3Ojo6Iys/RD84QzQ5OjcBCgoKDQwNGg8PGjclHyU3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3N//AABEIAJQA+QMBIgACEQEDEQH/xAAbAAEAAgMBAQAAAAAAAAAAAAAABQYBBAcDAv/EAEYQAAEDAwIDBQUDCwEFCQAAAAEAAgMEBREGIRIxQQcTUWF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b5OF0/6e4StP6qnad2n+bl6ZXjpaIak1VV6idk0FvDqC3MI2OMccn1936oLLpKxQabsNJa6fB7pmZHgY7yQ7ud8yphYGVlAREQEREBERAREQEREBERAREQEREBERAREQEREBERAREQFg8kRBxxlwnj01rvUTS38pPqpaYSkfBGwlrQB02GfUldQ03bqa02WhoaJnBBDAwNB5nbmfNEVEoiIoCIiAiIgIiICIiAiIgIiICIiAiIgIiICIiD/9k='
msgImg = MIMEImage(img, 'jpeg')
msgImg.add_header('Content-ID', '<image1>')
msgImg.add_header('Content-Disposition', 'inline', filename='signaure.jpeg')
msg.attach(msgImg)
"""
try:
with smtplib.SMTP(MAIL_SERVER_SMTP, MAIL_SERVER_SMTP_PORT) as smtpobj:
smtpobj.ehlo()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

from bs4 import BeautifulSoup
import base64

"""
This class is leveraged to handle the embedded images in mail body.
"""
class embeddedimagehandler:

"""
This function can be enhanced to store the image in S3 & re-use (if required)
Please note; in case of storing in S3. This function should be invoked before persisting to DB.
"""
def formatembeddedimage(self, content):
soup = BeautifulSoup(content, "html.parser")
img_nodes = soup.find_all("img")
embeddedimages = []
for img in img_nodes:
if 'base64' in img['src']:
imgsrc = img['src']
imagename = "image"+str(len(embeddedimages))
img['src'] = "cid:"+imagename
img['style'] = "width:180px;height:50px;"
imgbytes = imgsrc.split("base64,")[1]
embeddedimages.append({"cid": imagename, "bytes": base64.b64decode(str(imgbytes)), 'type': self.__getmimetype(imgsrc)})
return soup.prettify(), embeddedimages


def __suportedmimetypes(self):
return [
{ "prefix": "/9j/", "mimetype" : "image/jpg", "extension": "jpg"},
{ "prefix": "iVBORw0KGgo", "mimetype" : "image/png", "extension": "png"}
]


def __getmimetype(self, b64):
for entry in self.__suportedmimetypes():
if entry['prefix'] in b64:
return entry['extension']
1 change: 1 addition & 0 deletions request-management-api/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,5 @@ boto3==1.24.35
walrus==0.8.2
imap-tools==0.56.0
more-itertools==10.2.0
beautifulsoup4==4.12.3
-e git+https://github.com/bcgov/sbc-common-components.git#egg=sbc-common-components&subdirectory=python

0 comments on commit c9e60a8

Please sign in to comment.