I am interested in sending a text-body email with a csv attachment. This seems simple when I've used very small csvs (10 rows), but the emails wont send when I have larger attachments. My email attachment size limitation is 10MB, so I don't expect/intend to send anything larger than that, but I'm not able to attach anything even close to that size.
I am running python 2.7 code off of an AWS EC2 instance, in a streamsets jython stage, which may or may not affect my response.
## Make CSV to attach
csvString = 'some string of csv-type' # EX: 'header1, header2, header3, header4'
## Send response email
#### Set To/From/Subject
sender = 'no-reply@example.com'
recieversString = 'rec1@example.com, rec1@example.com'
recieversArray = recieversString.split(',')
subject = 'Job Complete'
msg = MIMEMultipart()
msg['From'] = sender
msg['To'] = recieversString
msg['Subject'] = subject
#### Set body ===========================
body = '''To: ''' + msg['To'] + '''
From: ''' + str(msg['From']) + '''
Subject: ''' + msg['Subject'] + '''
Files uploaded to AWS'''
#### ==================================
msgMIMEText = MIMEText(body, 'plain')
msg.attach(msgMIMEText)
#### ==================================
#### Set attachment
attMIMEBase = MIMEBase('text', 'csv')
attMIMEBase.set_payload(csvString)
Encoders.encode_base64(attMIMEBase)
attMIMEBase.add_header('Content-Disposition', 'attachment', filename='file_name')
msg.attach(attMIMEBase)
#### Send Email
try:
smtpObj = smtplib.SMTP('my.domain.example', 25)
smtpObj.sendmail(sender, recieversArray, msg.as_string())
print('response email sent')
except:
print('response email failed')
I have tried printing the size of many of the failed emails. Many of the files are less than 1 MB, but the email still fails. I've only copied the code I feel is useful for this question. Please let me know if there is other info that would be helpful. Thanks everyone.