468,467 Members | 2,652 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,467 developers. It's quick & easy.

Password Protection to Email attachment

Hi All,

i am currently reading file from azure blob storage and sending email . I would like to add password protection to the attachment.
below is my current code which is sending email with attachement

import base64
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import (Mail, Attachment, FileContent, FileName, FileType)
from azure.storage.blob import BlockBlobService

# mail details
to = To_address
from_email = From_Address
subject = Subject
content = '''
Test Content'''

# create mail object
message = Mail(
from_email = from_email,
to_emails = to,
subject = subject,
html_content = content

# read the content from azure blob storage
blob_service = BlockBlobService(account_name=Blob_Storage_Account , account_key=account_key)
## read the content inside blob
# read export file
export_file_data = blob_service.get_blob_to_bytes(Blob_Container, export_file_name)
export_file_mail_content = export_file_data.content

# create export file attachement
export_file_encoded = base64.b64encode(export_file_mail_content).decode( )
export_file_attachment = Attachment()
export_file_attachment.file_content = FileContent(export_file_encoded)
export_file_attachment.file_type = FileType('application/txt')
export_file_attachment.file_name = FileName(export_file_name.split('/')[-1])

# send mail with above attachment
mail = SendGridAPIClient(send_grid_api_key)
response = mail.send(message)
except Exception as e:
4 Days Ago #1
1 779
430 Expert 256MB
I would like to add password protection to the attachment.
Encrypt it before attaching.
20 Hours Ago #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Boris | last post: by
6 posts views Thread by Lou | last post: by
7 posts views Thread by juglesh | last post: by
1 post views Thread by kmladenovski | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.