Aug-23-2019, 03:30 PM
I found this code online to send emails with attachments. Currently I believe it sends "encoded" attachments as the data is unreadable. How can I send the text files as they are with no encoding.
Also I have this piece of code which create text extracts as per the ID given.
At the end of the code when I click y or n an email should be automatically sent out to the email provided as input.how can this be achieved.
Thanks
EMAIL CODE:
And as per the email provided above I should automatically pick the AB12345.txt file once the user clicks y or n at the end of the program and email the AB12345.txt to the email provided.
Also how can I create a small chat window and ask those details in the chat window.
Ideas are appreciated.
Thanks
Also I have this piece of code which create text extracts as per the ID given.
At the end of the code when I click y or n an email should be automatically sent out to the email provided as input.how can this be achieved.
Thanks
EMAIL CODE:
import smtplib import base64 filename = "C:/Users/km041320/MKR/KM111111.txt" fo = open(filename, "rb") filecontent = fo.read() sender = 'SENDER EMAIL' reciever = 'RECIEVER EMAIL' marker = "AUNIQUEMARKER" body =""" This is a test email to send an attachement. """ # Define the main headers. part1 = """From: From Person <[email protected]> To: To Person <[email protected]> Subject: Sending Attachement MIME-Version: 1.0 Content-Type: multipart/mixed; boundary=%s --%s """ % (marker, marker) # Define the message action part2 = """Content-Type: text/plain %s --%s """ % (body,marker) # Define the attachment section part3 = """Content-Type: multipart/mixed; name=\"%s\" Content-Disposition: attachment; filename=%s %s --%s-- """ %(filename, filename, marker) message = part1 + part2 + part3 try: smtpObj = smtplib.SMTP('smtplb.xxxxxx.com') smtpObj.sendmail(sender, reciever, message) print ("Successfully sent email") except Exception: print ("Error: unable to send email") MY CODE: import datetime from datetime import datetime n = 5 while n > 0: id = check_id() with open("C:\\Users\\ABC\\DEF\\" "%s.txt" % id, "a") as file: name = check_name() Doctor = check_Doctor() ApptDate = check_date() phone = check_phone() EmailID = input("Please provide your email to confirm your appointment: ") dtstamp = datetime.today().strftime('%Y-%m-%d %H:%M:%S') file.write(name+ "|" +Doctor+ "|" +ApptDate+ "|" +EmailID+ "|" +phone+ "|" +dtstamp+ "\n") MoreData = input("Do you need to make any new Appointments? y/n :") if MoreData != "y": n= -1So if the ID is AB12345.It creates a text file AB12345.txt.
And as per the email provided above I should automatically pick the AB12345.txt file once the user clicks y or n at the end of the program and email the AB12345.txt to the email provided.
Also how can I create a small chat window and ask those details in the chat window.
Ideas are appreciated.
Thanks