Below code is not showing any error when run, but it is still not sending/receiving email with attachment:
import email
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email import header
from email.mime.application import MIMEApplication
def email_from_S3(self,S3,senderFile):
print('Sending Email...')
Sender = '[email protected]'
Recipient ='[email protected]'
Attachment = 'C:/Users/mittas1/Downloads/'+senderFile
S3.s3_client.download_file(S3.bucket,'output/'+senderFile,Attachment)
msg = MIMEMultipart()
msg['Subject'] = 'CRD_Extract'
msg['From'] = Sender
msg['To'] = Recipient
textpart = MIMEText('The output file was downloaded from S3')
msg.attach(textpart)
att = MIMEApplication(open(Attachment, 'rb').read())
att.add_header('Content-Disposition','attachment',filename=Attachment)
msg.attach(att)
try:
response = S3.ses_client.send_raw_email(
Source=Sender,
Destinations=[Recipient],
RawMessage={"Data":msg.as_string()}
)
except ClientError as e:
print(e.response['Error']['Message'])
else:
print("Email sent! Message ID:",response['MessageId'])