Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SMTP problem
#1
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?
Reply
#2
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..."?
Reply
#3
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?
Reply
#4
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.
Reply
#5
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
Reply
#6
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.
Reply
#7
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)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Send email with smtp without using Mimetext mgallotti 0 678 Feb-01-2023, 04:43 AM
Last Post: mgallotti
  send email smtp rwahdan 0 1,754 Jun-19-2021, 01:28 AM
Last Post: rwahdan
  TimeOutError when trying to initiate smtplib.SMTP thecosmos 0 3,295 Jun-19-2020, 05:30 AM
Last Post: thecosmos
  Sending an email with attachment without using SMTP? PythonNPC 5 3,115 May-05-2020, 07:58 AM
Last Post: PythonNPC
  Issue with text encoding ans smtplib.SMTP.sendmail() JustSomeUsername383 1 4,109 Jul-23-2019, 03:15 PM
Last Post: JustSomeUsername383
  python 'SMTP debugging server' not starting local error pcsailor 1 3,407 Nov-26-2018, 10:13 PM
Last Post: micseydel
  "Raise SMTPException("SMTP AUTH extension not supported by server.") NajeebUllah 3 7,919 Mar-16-2018, 09:45 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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