Il messaggio di errore é eloquente. Ti sta dicendo che texfile non sa dove trovarlo. Tranne alcuni casi dove le variabili vengono creati al volo esempio: for numero in numeri, dove numero é la variabile creata al volo per iterare numeri, Le variabili vanno definite prima. Questa è una delle basi della programmazione. Un consiglio, segui i consigli di chi ti legge possibilmente senza polemiche.
Il ven 23 ago 2019, 15:17 antonio taccetti <antonio.tacce...@gmail.com> ha scritto: > Il listato è questo: > # Import smtplib for the actual sending function > import smtplib > > # Import the email modules we'll need > from email.message import EmailMessage > > # Open the plain text file whose name is in textfile for reading. > with open(textfile) as fp: > # Create a text/plain message > msg = EmailMessage() > msg.set_content(fp.read()) > > # me == the sender's email address > # you == the recipient's email address > msg['Subject'] = 'The contents of %s' % textfile > msg['From'] = me > msg['To'] = you > > # Send the message via our own SMTP server. > s = smtplib.SMTP('localhost') > s.send_message(msg) > s.quit() > > anche se faccio così, non funziona, ma anzi da essore: > Traceback (most recent call last): > File > "C:\Users\leona\AppData\Local\Programs\Python\Python37\Tools\scripts\posta\lists-Creare-inviare-messaggio-di-testo.py", > line 20, in <module> > msg['Subject'] = 'The contents of %s' % textfile > NameError: name 'textfile' is not defined > > Io ho Python 3.7, sarà mica cheè è per Python 2.x? > Ciao > > > *Le informazioni contenute in questo messaggio di posta elettronica sono > riservate e confidenziali e ne è vietata la diffusione in qualsiasi modo o > forma. Qualora Lei non fosse la persona destinataria del presentemessaggio, > La invitiamo a non diffonderlo e ad eliminarlo, dandone gentilmente > comunicazione al mittente.* > *The information included in this e-mail and any attachments are > confidential and may also be privileged.If you are not the correct > recipient, you are kindly requested to notify the sender immediately, to > cancel it and not to disclose the contents to any other person.* > > > Il giorno ven 23 ago 2019 alle ore 14:19 Carlos Catucci < > carlos.catu...@gmail.com> ha scritto: > >> >> >> On Fri, 23 Aug 2019 at 14:08, antonio taccetti < >> antonio.tacce...@gmail.com> wrote: >> > >> > Scusate la domanda banale, sono neofita di Python 3.7, >> > sto provando il codice della pagina >> > >> https://docs.python.org/3/library/email.examples.html?highlight=read%20mail >> > First, let’s see how to create and send a simple text message (both the >> text content and the addresses may contain unicode characters): >> > >> > Non riesco a capire perchè mi da l'errore: >> > Traceback (most recent call last): >> > File >> "C:\Users\leona\AppData\Local\Programs\Python\Python37\Tools\scripts\posta\lists-Creare-inviare-messaggio-di-testo.py", >> line 13, in <module> >> > with open(textfile) as fp: >> > NameError: name 'textfile' is not defined >> > Il file c'è ed è bnella stessa cartella Cosè che non capisco? >> > Dov'è che sbaglio? >> >> >> textfile e' una variabile, o ci metti il nome del file o la inizializzi >> da qualche parte con il nom del file che vuoi usare. >> Il commento stesso dice >> >> # Open the plain text file whose name is in textfile for reading. >> >> In pratica textfile deve essere inizializzata con il nome del file >> >> Carlos >> -- >> EZLN ... Para Todos Todo ... Nada para nosotros >> _______________________________________________ >> Python mailing list >> Python@lists.python.it >> https://lists.python.it/mailman/listinfo/python >> > _______________________________________________ > Python mailing list > Python@lists.python.it > https://lists.python.it/mailman/listinfo/python >
_______________________________________________ Python mailing list Python@lists.python.it https://lists.python.it/mailman/listinfo/python