Esempio n. 1
0
def mytest():
    dhnio.SetDebug(30)

##    filename = "identity.pyc"              # just some file to send

    pop_info = [
        settings.getEmailAddress(),
        settings.getPOPHost(),
        settings.getPOPPort(),
        settings.getPOPUser(),
        settings.getPOPPass(),
        settings.getPOPSSL()]

    smtp_info = [
        settings.getEmailAddress(),
        settings.getSMTPHost(),
        settings.getSMTPPort(),
        settings.getSMTPUser(),
        settings.getSMTPPass(),
        settings.getSMTPSSL()]



##    smtp_info = smtp2_info


    if len(sys.argv) == 1:
        print pop_info
        if not check_info(pop_info):
            print 'need POP info. see user configuration file'
            sys.exit()
        mylistener = None
        def receive_file(x):
            print 'receive 1 file.', x
##            mylistener.stopListening()
        mylistener = receive(pop_info, receive_event=receive_file)
##        reactor.run()
    elif len(sys.argv) == 3:
##        send(filename, pop_info[0])
        send(sys.argv[2], sys.argv[1], reactor_stop=True, use_smtplib=False)
    elif len(sys.argv) == 4 and sys.argv[1].lower() == '-p':
        send_public(sys.argv[3], sys.argv[2], reactor_stop=True, use_smtplib=False)
    else:
        print 'usage:'
        print 'to receive:   transport_email'
        print 'to send   :   transport_email [e-mail] [filename]'
        print 'to send from public datahaven server:'
        print '              transport_email -p [e-mail] [filename]'
        sys.exit(0)
Esempio n. 2
0
def send_public(filename, email, subject = 'datahaven_transport', reactor_stop=False, use_smtplib=False):
    smtp_info = [
            settings.getEmailAddress(),   #0
            settings.getSMTPHost(),       #1
            settings.getSMTPPort(),       #2
            settings.getSMTPUser(),       #3
            settings.getSMTPPass(),       #4
            settings.getSMTPSSL(),        #5
            settings.getSMTPNeedLogin()]  #6
    def ok(x):
        dhnio.Dprint(14, 'transport_email.send_public.ok: sending done')
##        if misc.transport_control_using():
        transport_control.sendStatusReport(email, filename,
            'finished', 'email')  # only one outstanding send per host
        transport_control.log('email', 'message successful sent')
        poll().send()
        if reactor_stop:
            reactor.stop()
    def fail(x):
        dhnio.Dprint(1, 'transport_email.send_public.fail NETERROR sending email \n' + str(x.getErrorMessage()))
##        transport_control.msg('e', 'error sending email: ' + str(x.getErrorMessage()))
##        transport_control.connectionStatusCallback('email', smtp_info[0], x, 'error sending email')
        transport_control.sendStatusReport(email, filename,
            'failed', 'email',
            x, 'error sending email')
        transport_control.log('email', 'NETERROR sending email')
        if reactor_stop:
            reactor.stop()

    res = sendTwistedMailAuth(
        smtp_info[1],
        smtp_info[2],
        smtp_info[3],
        smtp_info[4],
        smtp_info[5],
        smtp_info[6],
        smtp_info[0],
        email,
        subject,
        filename)
    res.addCallback(ok)
    res.addErrback(fail)
    return res
Esempio n. 3
0
def send(filename, email, subject = 'datahaven_transport', reactor_stop=False, use_smtplib=False):
    transport_control.log('email', 'start sending to ' + email)
    smtp_info = [
            settings.getEmailAddress(),   #0
            settings.getSMTPHost(),       #1
            settings.getSMTPPort(),       #2
            settings.getSMTPUser(),       #3
            settings.getSMTPPass(),       #4
            settings.getSMTPSSL(),        #5
            settings.getSMTPNeedLogin()]  #6

    if smtp_info[0].strip() == '' or smtp_info[1].strip() == '':
        dhnio.Dprint(1, 'transport_email.send empty mailbox info. check your email options')
##        transport_control.msg('e', 'empty mailbox info. check your email options')
##        transport_control.connectionStatusCallback('email', email, None, 'empty mailbox info. check your email options')
        transport_control.sendStatusReport(email, filename,
            'failed', 'email',
            None, 'empty mailbox info. check your email options')
        return

##    print smtp_info
##    smtp_info = smtp3_info
    if not os.path.isfile(filename):
        dhnio.Dprint(1, 'transport_email.send wrong file name: %s' % filename)
##        transport_control.msg('e', 'wrong file name %s' % filename)
        return
    from_address = smtp_info[0]
    dhnio.Dprint(8, 'transport_email.send  from:%s to:%s' % (from_address, email))

    if use_smtplib:
        #send via smtplib
        try:
            send_smtplib(
                smtp_info[1],
                smtp_info[3],
                smtp_info[4],
                smtp_info[5],
                from_address,
                email,
                subject,
                filename)
        except:
            dhnio.Dprint(1, 'transport_email.send NETERROR sending email ' + dhnio.formatExceptionInfo())
##            transport_control.msg('e', 'Error sending email')
            transport_control.log('email', 'error sending email')
##            transport_control.connectionStatusCallback('email', email, None, 'error sending email')
            transport_control.sendStatusReport(email, filename,
                'failed', 'email',
                None, 'error sending email')
            return
##        if misc.transport_control_using():
        transport_control.sendStatusReport(email, filename,
            'finished', 'email')  # only one outstanding send per host
        transport_control.log('email', 'done')
        poll().send()
    else:
        #Send via Twisted
        def ok(x):
            dhnio.Dprint(14, 'transport_email.send.ok: sending done')
##            if misc.transport_control_using():
            # only one outstanding send per host
            transport_control.sendStatusReport(email, filename,
                'finished', 'email')
            transport_control.log('email', 'message successful sent')
            poll().send()
            if reactor_stop:
                reactor.stop()
        def fail(x):
##            if misc.transport_control_using():
            dhnio.Dprint(1, 'transport_email.send.fail NETERROR sending email \n' + str(x.getErrorMessage()))
##            transport_control.msg('e', 'error sending email: '  + str(x.getErrorMessage()) )
##            transport_control.connectionStatusCallback('email', smtp_info[0], x, 'error sending email')
            transport_control.sendStatusReport(email, filename,
                'failed', 'email',
                x, 'error sending email')
            transport_control.log('email', 'error sending email'  + str(x.getErrorMessage()))
            if reactor_stop:
                reactor.stop()

        if smtp_info[6]:
            #1th method
            res = sendTwistedMailAuth(
                smtp_info[1],
                smtp_info[2],
                smtp_info[3],
                smtp_info[4],
                smtp_info[5],
                smtp_info[6],
                from_address,
                email,
                subject,
                filename)
        else:
            #2th method:
            res = sendTwistedMail(
                smtp_info[1],
                smtp_info[0],
                email,
                subject,
                filename,
                smtp_info[2])
        res.addCallback(ok)
        res.addErrback(fail)
        return res