#import os #import smtplib #from email import encoders #from email.mime.base import MIMEBase #from email.mime.multipart import MIMEMultipart #COMMSPACE = ', ' def sendgeotifs(attachments,email,fieldaddress,date,whitelabel): 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 = ', ' #if email.find('dbehr01@gmail.com')>=0: # email = 'ankuromar296@gmail.com' sender = 'support@farmonaut.com' gmail_password = 'ankur@A8' recipient = email outer = MIMEMultipart() year = date[0:4] month = date[4:6] day = date[6:] date = year+'-'+month+'-'+day+' (in yyyy-mm-dd)' outer['Subject'] = 'Farmonaut | Satellite Results | Date: '+ date+' | Field Address: '+fieldaddress + ' Open on Android, iOS or Web-App' outer['To'] = recipient outer['From'] = sender 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. The next satellite movement is expected in the next 4-10 days. Please find attached below the GEOTIFF images of your field as well as a comprehensive report of all the results. These images can be used in third-party remote sensing/GIS softwares. 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.\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' 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" html_message = """ Document """ # html_message = """ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # """ outer.attach(MIMEText(html_message,"html")) outer.attach(MIMEText(message,"plain")) 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.") 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: ") if __name__ == '__main__': main()