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 SendGridAPIClie nt
from sendgrid.helper s.mail import (Mail, Attachment, FileContent, FileName, FileType)
from azure.storage.b lob import BlockBlobServic e
# 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 = BlockBlobServic e(account_name= Blob_Storage_Ac count, account_key=acc ount_key)
## read the content inside blob
# read export file
export_file_dat a = blob_service.ge t_blob_to_bytes (Blob_Container , export_file_nam e)
export_file_mai l_content = export_file_dat a.content
# create export file attachement
export_file_enc oded = base64.b64encod e(export_file_m ail_content).de code()
export_file_att achment = Attachment()
export_file_att achment.file_co ntent = FileContent(exp ort_file_encode d)
export_file_att achment.file_ty pe = FileType('appli cation/txt')
export_file_att achment.file_na me = FileName(export _file_name.spli t('/')[-1])
message.add_att achment(export_ file_attachment )
# send mail with above attachment
try:
mail = SendGridAPIClie nt(send_grid_ap i_key)
response = mail.send(messa ge)
except Exception as e:
print(str(e))
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 SendGridAPIClie nt
from sendgrid.helper s.mail import (Mail, Attachment, FileContent, FileName, FileType)
from azure.storage.b lob import BlockBlobServic e
# 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 = BlockBlobServic e(account_name= Blob_Storage_Ac count, account_key=acc ount_key)
## read the content inside blob
# read export file
export_file_dat a = blob_service.ge t_blob_to_bytes (Blob_Container , export_file_nam e)
export_file_mai l_content = export_file_dat a.content
# create export file attachement
export_file_enc oded = base64.b64encod e(export_file_m ail_content).de code()
export_file_att achment = Attachment()
export_file_att achment.file_co ntent = FileContent(exp ort_file_encode d)
export_file_att achment.file_ty pe = FileType('appli cation/txt')
export_file_att achment.file_na me = FileName(export _file_name.spli t('/')[-1])
message.add_att achment(export_ file_attachment )
# send mail with above attachment
try:
mail = SendGridAPIClie nt(send_grid_ap i_key)
response = mail.send(messa ge)
except Exception as e:
print(str(e))
Comment