#import os #import smtplib #from email import encoders #from email.mime.base import MIMEBase #from email.mime.multipart import MIMEMultipart #COMMSPACE = ', ' def sendonlyreport(attachments,email,fieldaddress,date,whitelabel, whitelabelEmail, whitelabelPassword): 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 import traceback #COMMASPACE = ', ' if whitelabelEmail is not None: sender = whitelabelEmail gmail_password = whitelabelPassword else: sender = 'support@farmonaut.com' gmail_password = 'ankur@A8' recipient = email if recipient == 'aditi.gautam@cgiar.org': recipient = '' outer = MIMEMultipart() outer['To'] = recipient outer['From'] = sender year = date[0:4] month = date[4:6] day = date[6:] date = year+'-'+month+'-'+day+' (in yyyy-mm-dd)' outer['Subject'] = whitelabel +' | Satellite Results | Date: '+ date+' | Field Address: '+fieldaddress + ' Open on Android, iOS or Web-App' print(whitelabel) message = 'Hello,'+ '\n\nThe new results for your field at the address: '+fieldaddress+' are available now. The Satellite crossed over your field on '+date+' . The results are best understood when directly accessed from our app. Please check My Fields section of the app to check all the results. The next satellite movement is expected in the next 4-10 days. Please find attached below a comprehensive report of all the results. 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 or on our WhatsApp Number: +91-6366026267 with the name of the images you want to be reviewed by us.\n\nNote: If you want to visualize the satellite results in third-party remote sensing softwares and require the images in GEOTIFF format then please let us know. These images are provided on a request basis.\n\nPlatforms:\nAndroid: https://play.google.com/store/apps/details?id=com.farmonaut.android\niOS: https://apps.apple.com/us/app/farmonaut/id1489095847?ls=1\nWeb App: https://farmonaut.com/web-app\n\nRegards' if "farmonaut" not in whitelabel: return whitelabel_url = "https://farmonaut.com/web-app" if "f4b-sat" in whitelabel: whitelabel_url = "https://f4b-sat.web.app" elif "troforte"in whitelabel: whitelabel_url = "https://app.trofortefarming.com.au" elif "linxag" in whitelabel: whitelabel_url == "https://linxag.web.app" elif "biopixel" in whitelabel: whitelabel_url = "https://biopixelsolutions.web.app" else: outer.attach(MIMEText(message,"plain")) html_message = """ Document """ outer.attach(MIMEText(html_message,"html")) 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 Exception as e: print(traceback.format_exc()) if __name__ == '__main__': main()