Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Send data in email attachment every hour

Hi, I want send data in email attachment (.txt file) every hour remote.. And if I compiles to exe (with py2exe) get error on line
Code
while True:

Actually code to send email:
Code
def mail(serverURL=smtp.seznam.cz, sender='', to='', subject='', text=''):
    """
    Usage:
    """
    mail('smtp.seznam.cz', '[email protected]', '[email protected]', 'OMGWTF', 'Hello Marty! :) I have gift for you in attachment.')
    
    message = StringIO.StringIO()
    writer = MimeWriter.MimeWriter(message)
    writer.addheader('Subject', subject)
    writer.startmultipartbody('mixed')
    # start off with a text/plain part
    part = writer.nextpart()
    body = part.startbody('text/plain')
    body.write(text)
    # now add an attachment
    part = writer.nextpart()
    part.addheader('Content-Transfer-Encoding', 'base64')
    body = part.startbody('text/plain')
    base64.encode(open(logins.txt, 'rb'), body)
    # finish off
    writer.lastpart()
    # send the mail
    smtp = smtplib.SMTP(s)
    smtp.sendmail(sender, to, message.getvalue())
    smtp.quit()

    if __name__ == '__main__':
    while True:
        mail()
        time.sleep(3600)
(May 6, 2017 05:17 AM)ASlopaR Wrote:  Hi, I want send data in email attachment (.txt file) every hour remote.. And if I compiles to exe (with py2exe) get error on line

your while statement doesn't look indented
Code
if __name__ == '__main__':
        while True:
            mail()
            time.sleep(3600)
i like python lua js
Would be great if you could include the error as well? :) There is normally a few lines called Traceback, that would help out a lot.
[Random signature]
Actually problem is removed, and I get new problem.
I have included to Python 2.7.13 APScheduler module (module version 3.3.1)
And I will import in code:

Code
from apscheduler.scheduler import Scheduler

Error message:
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
from apscheduler.scheduler import Scheduler
ImportError: No module named apscheduler.scheduler
Code
serverURL=smtp.seznam.cz

ServerURL argument needs to be a string, like so:

Code
serverURL='smtp.seznam.cz'


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by FlzdudenMar 23, 2019 10:54 PM 16 418 Mar 23, 2019 10:54 PM
Last Post: +Haze
[C] by F.A.S.TMar 9, 2019 06:16 PM 4 235 Mar 9, 2019 06:16 PM
Last Post: YouthInAsia
[.NET] by CrackIt™Dec 22, 2018 03:24 AM 1 142 Dec 22, 2018 03:24 AM
Last Post: itcorp