#import os #import smtplib #from email import encoders #from email.mime.base import MIMEBase #from email.mime.multipart import MIMEMultipart #COMMSPACE = ', ' def sendemail(attachments,email,name,imageid,total_refund,unsuccessful_dates): import os import smtplib from email import encoders from email.mime.text import MIMEText from email.mime.base import MIMEBase from email.mime.multipart import MIMEMultipart #COMMASPACE = ', ' sender = 'support@farmonaut.com' gmail_password = 'ankur@A8' recipient = email outer = MIMEMultipart() outer['Subject'] = 'Farmonaut - On Demand Satellite Imagery Results - Request ID: '+imageid outer['To'] = recipient outer['From'] = sender if total_refund > 0: message = 'Hello ' +name +','+ '\n\nPlease find attached the images requested through our On Demand Satellite Imagery Service. There are a few images which could not be processed/generated. This happens when during the revolution of the satellite, it failed to capture imagery of the location. You are elgible for refund for these images. Refund process will be initiated within 24 hours and will be credited back to your Farmonaut Balance. A complete report is attached below. Our system has processed images with the best standards. However, if some of the images do not satisfy your expectations, then revert back on this thread with the name of the images you want to be reviewed by us. If upon review, we find out that the images are indeed not meeting the expectations, the equivalent amount of money will be credited back. Rest assured, we are committed to provide the best services to our customers.\n\n' + unsuccessful_dates + '\n\n'+'Total Refund: $'+str(total_refund)+'\n\nRegards,\nFarmonaut Support' #outer['Body'] = "sample" else: message = 'Hello ' +name +','+ '\n\nPlease find attached the images requested through our On Demand Satellite Imagery Service. Our system has processed images with the best standards. However, if some of the images do not satisfy your expectations, then revert back on this thread with the name of the images you want to be reviewed by us. If upon review, we find out that the images are indeed not meeting the expectations, the equivalent amount of money will be credited back. Rest assured, we are committed to provide the best services to our customers.\n\nRegards,\nFarmonaut Support' outer.attach(MIMEText(message)) outer.preamble = 'You will not see this in a MIME-aware mail reader.\n' attachments = attachments for file in attachments: try: with open(file,'rb') as fp: msg = MIMEBase('application',"octet-stream") msg.set_payload(fp.read()) encoders.encode_base64(msg) msg.add_header('Content-Disposition','attachment',filename=os.path.basename(file)) #text = "sample text" outer.attach(msg) except: print("Unable to open one of the attachments. Error: ",sys.exc_info()[0]) composed = outer.as_string() try: # with smtplib.SMTP('smtp.gmail.com',587) as s: # s.ehlo() # s.starttls() # s.ehlo() # s.login(sender,gmail_password) # s.sendmail(sender,recipient, composed) # s.close() print("Email sent!") except: print("Unable to send the email. Error: ",sys.exc_info()[0]) if __name__ == '__main__': main()