![]() |
SMTP problem - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: SMTP problem (/thread-26651.html) |
SMTP problem - MajK - May-08-2020 Hello, i have programed a smaller program and when i run it in pycharm everything works fine, but when i save this project on desktop and want to run it it skips the last part where is the smtp. Any clues how to solve this? RE: SMTP problem - ndc85430 - May-08-2020 It would help if you gave more details, like a minimal yet complete code sample and a bit more of a description about the problem. How exactly are you running the program and what do you mean by "it skips..."? RE: SMTP problem - MajK - May-08-2020 So i figured out that the program works in python shell but not in command, so how can i fix that? i think its because i have imported smtplib module and ran it as script mby? RE: SMTP problem - ndc85430 - May-08-2020 Again, post a minimal code sample, show how you're running it and explain what doesn't work. We can't see your screen, so it's impossible to help you debug the problem without information. RE: SMTP problem - MajK - May-08-2020 while datetime.datetime.now() < start: time.sleep(1) email = "examle.abcdefg" password = "12345" send_to_email = "a" subject = "Odvzem vzorca" message = "b" msg = MIMEMultipart() msg["From"] = email msg["To"] = send_to_email msg["subject"] = subject msg.attach(MIMEText(message, "plain")) server = smtplib.SMTP("smtp.gmail.com", 587) server.starttls() server.login(email, password) text = msg.as_string() server.sendmail(email, send_to_email, text) server.quit() it skips this part but in python shell works RE: SMTP problem - ndc85430 - May-09-2020 I did say minimal yet complete, sigh. Is it failing to enter the while loop? If so, what is the value of start ? Can you show examples of output where it's working OK and where it isn't? It would probably help to add some calls to print to see what's being executed, you know, just regular debugging stuff.Also, please post code within "[python]" tags, because that preserves the indentation and adds line numbering and syntax highlighting. RE: SMTP problem - MajK - May-09-2020 print(" Nov vnos ( Vnesite 1)\n Pregled ( Vnesite 2 ) \n") zac_vnos = input("> ") if zac_vnos in ["nov vnos", "Nov vnos", "N", "n", "1"]: import smtplib, datetime, time from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart try: ime = input("Vnesite ime vzorca: ") oznaka = input("Vnesite oznako vzorca: ") datum = input("Vnesite današnji datum: ") pogoj = input("Vnesite stresni pogoj: ") opombe = input("Vnesite opombe: ") komora = input("Vnesite oznako komore: ") info = f"\n {ime} - {oznaka} - {datum} - {pogoj} - {opombe} - {komora} " usr_years = int(input("Vnesite število let: ")) usr_months = int(input("Vnesite število mesecev: ")) usr_days = int(input("Vnesite število dni: ")) if usr_years == 1: usr_days = 365 + usr_days elif usr_years == 2: usr_days = 730 + usr_days elif usr_years == 3: usr_days = 1095 + usr_days if usr_months == 1: usr_days = 31 + usr_days elif usr_months == 2: usr_days = 61 + usr_days elif usr_months == 3: usr_days = 92 + usr_days elif usr_months == 4: usr_days = 123 + usr_days elif usr_months == 5: usr_days = 154 + usr_days elif usr_months == 6: usr_days = 184 + usr_days elif usr_months == 7: usr_days = 215 + usr_days elif usr_months == 8: usr_days = 244 + usr_days elif usr_months == 9: usr_days = 276 + usr_days elif usr_months == 10: usr_days = 306 + usr_days elif usr_months == 11: usr_days = 336 + usr_days elif usr_months == 12: usr_days = 365 + usr_days if usr_years == "": usr_days = 0 + usr_days elif usr_months == "": usr_days = 0 + usr_days elif usr_days == "": usr_days = 0 + usr_days t_date = datetime.date.today() extract_date = datetime.timedelta(usr_days) end_date = t_date + extract_date non_w_day = datetime.date.weekday(end_date) holidays = [datetime.date(end_date.year, 1, 1), # Novo leto datetime.date(end_date.year, 1, 2), # Novo leto datetime.date(end_date.year, 2, 8), # Presernov dan datetime.date(end_date.year, 4, 27), # Dan upora proti okupatorju datetime.date(end_date.year, 5, 1), # Dan dela datetime.date(end_date.year, 5, 2), # Dan dela datetime.date(end_date.year, 6, 25), # Dan drzavnosti datetime.date(end_date.year, 11, 1), # Dan spomina na mrtve datetime.date(end_date.year, 12, 26), # Dan samostojnosti in enotnosti datetime.date(end_date.year, 12, 25), # Bozic datetime.date(end_date.year, 10, 31), # Dan reformacije datetime.date(end_date.year, 8, 15), # Marijino vnebovzetje datetime.date(2020, 4, 13), # Velikonocni ponedeljek datetime.date(2021, 5, 4), # Velikonocni ponedeljek datetime.date(2022, 4, 18), # Velikonocni ponedeljek datetime.date(2023, 4, 10), # Velikonocni ponedeljek datetime.date(2024, 4, 1), # Velikonocni ponedeljek datetime.date(2025, 4, 21)] # Velikonocni ponedeljek while end_date in holidays: end_date += datetime.timedelta(days=1) if non_w_day in [5]: end_date += datetime.timedelta(2) else: pass vnos = open("Pregled.txt", "a") vnos.write(f"\n {ime} - {oznaka} - {datum} - {pogoj} - {opombe} - {komora} - {end_date}") vnos.close() dobitniki = [] # prejemniki while True: print("Vnesite prejemnika ( Ce ne zelite vnesti prejemnika pritisnite enter ): ") prejemnik = input() if prejemnik == '': break dobitniki = dobitniki + [prejemnik] else: pass start = datetime.datetime(end_date.year, end_date.month, end_date.day, 8, 0, 0) while datetime.datetime.now() < start: time.sleep(1) email = "example.abcd" password = "123" for prejemnik in dobitniki: send_to_email = prejemnik subject = "Odvzem vzorca" message = info msg = MIMEMultipart() msg["From"] = email msg["To"] = send_to_email msg["subject"] = subject msg.attach(MIMEText(message, "plain")) server = smtplib.SMTP("smtp.gmail.com", 587) server.starttls() server.login(email, password) text = msg.as_string() server.sendmail(email, send_to_email, text) server.quit() except: ValueError elif zac_vnos in ["pregled", "Pregled", "P", "p", "2"]: with open("Pregled.txt", "r") as f: for line in f: print(line, end="") thats the whole program but i dont have a error, the problem is where i run the program it works in python shell and pycharm but when i try to run it in python terminal it ends the program at the end of while datetime.datetime.now() < start: time.sleep(1) |