Python Forum
Email newly created file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Email newly created file
#1
def check_id():
    while True:
        id = input("Please enter your ID: ")
        if len(id) == 8 and ' 'not in id and id[0:2].isalpha()==True and id[2:8].isdigit()==True:
            print("Thanks for the input")
            return id
        else:
            print("Input must have only 8 characters and should not have whitespaces,the first 2 characters must be alphabets,please re-enter your ID")

def check_name():
    while True:
        name = input("Please provide your name: ")
        if len(name)!=0 and name.replace(" ","").isalpha() and name[0:1] is not ' ':
            print("Thanks for the input")
            return name
        else:
            print("The name entered is an empty string or has whitespaces or has characters other than alphabets,please re-enter your name")

def check_Doctor():
    while True:
        name = input("Please provide the name of the doctor you would like to book an appointment with: ")
        if len(name)!=0 and name.replace(" ","").isalpha() and name[0:1] is not ' ':
            print("Thanks for the input")
            return name
        else:
            print("The name entered is an empty string or has whitespaces or has characters other than alphabets,please re-enter the Doctor's name")


def check_date():
    from datetime import datetime
    while True:
        inputdate = input("Please enter date in DDMMYYY format: ")
        ApptDateReq = datetime.strptime(inputdate, "%d/%m/%Y")
        present = datetime.now()
        if ApptDateReq.date() > present.date():
            print("Thanks")
            return inputdate
        else:
            print("You cannot book an appointment in the past,please re-enter date")

def check_phone():
    while True:
        phone = input("Please provide your phone number: ")
        if all((len(phone) == 10, phone.isdigit())):
            print("Thanks for the input,you have entered",phone)
            return phone
        else:
            print("The phone number entered is an empty string or has whitespaces or has alphabets,please re-enter the phone number")

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= -1
How do I autoemail the text file which is created as an attachment once the user clicks y or n to the email
Stored in ‘Email’

Thanks
Reply
#2
There are a couple options for sending email programatically:

1. The smtplib module in the standard library if you have access to an SMTP server. See the sendemail method on the SMTP class and the example at the bottom of the file.

2. An email sending web service. For example, if you use Gmail, Google provide the Gmail API, a REST API for interacting with Gmail.
Reply
#3
Thanks
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020