コード例 #1
0
ファイル: views.py プロジェクト: jcm-shove-it/newsletter
def sendmail(request, email_id):
    userName = request.user.username
    listLetterSender = ListletterSender.objects.filter(user__username=request.user.username)[0]

    selected_email = email_id
    selected_groups = None
    available_groups = EmailTargetGroup.objects.filter(user__user__username=request.user.username)

    mode = ''
    sup = InboxSupplier()
    sup.login(mail_host, listLetterSender.mailUsername, listLetterSender.mailPassword)
    m_email = sup.getEmail(int(email_id))
    sup.logout()

    try:
        was_send = request.POST['_send']
        mode = 'send'
    except:
        mode = 'approve'

    if mode == 'send':
        mode = 'send'
        sender  = SmtpSender()
        sender.login(mail_host, listLetterSender.mailUsername, listLetterSender.mailPassword)
        selected_groups = Helper.getGroups(request)
        selected_email_targets = Helper.getUsersOfGroups(selected_groups, listLetterSender)

        mime_mail = Parser().parsestr(m_email.body)
        time1 = time.time()
        lla = sender.sendMail(mime_mail, selected_email_targets, listLetterSender)
        sender.logout()
        time2 = time.time()
        seconds_elapsed = (time2 - time1)
        
        return render_to_response('listletter/approve.html', {
            'email':m_email,
            'selected_groups':selected_groups,
            'action':mode,
            'err_cnt':len(lla.senderror_set.all()),
            'suc_cnt':len(lla.sendaction_set.all()),
            'seconds_elapsed':seconds_elapsed,
            'listletteraction':lla,
            'isMails':True,
            })

    else:
        return render_to_response('listletter/approve.html', {
            'email':m_email,
            'available_groups':available_groups,
            'action':mode,
            'isMails':True,
            'email_sender':listLetterSender.emailAddress,
            })
コード例 #2
0
def deletemail(request, email_id):
    listLetterSender = ListletterSender.objects.filter(
        user__username=request.user.username)[0]

    sup = InboxSupplier()
    sup.login(mail_host, listLetterSender.mailUsername,
              listLetterSender.mailPassword)
    m_email = sup.getEmail(int(email_id))

    try:
        if request.POST['post'] == 'yes':
            try:
                sup.deleteMail(email_id)
                sup.logout()
            except Exception as ex:
                message = u'Delete message %s from %s failed: ' % (
                    m_email.getSubject(), m_email.getDate())
                message += ex.__unicode__()
                return render_to_response(
                    'listletter/maildelete.html', {
                        'email': m_email,
                        'email_name': m_email.getSubject(),
                        'email_deleted': 'False',
                        'isMails': True,
                        'message': message,
                        'error': 'True'
                    })
            return render_to_response(
                'listletter/maildelete.html', {
                    'email': m_email,
                    'email_name': m_email.getSubject(),
                    'email_deleted': 'True',
                    'isMails': True,
                })
    except Exception as e:
        pass

    return render_to_response(
        'listletter/maildelete.html', {
            'email': m_email,
            'email_name': m_email.getSubject(),
            'email_deleted': 'False',
            'isMails': True,
        })
コード例 #3
0
ファイル: views.py プロジェクト: jcm-shove-it/newsletter
def deletemail(request, email_id):
    listLetterSender = ListletterSender.objects.filter(user__username=request.user.username)[0]

    sup = InboxSupplier()
    sup.login(mail_host, listLetterSender.mailUsername, listLetterSender.mailPassword)
    m_email = sup.getEmail(int(email_id))
    
    try:
        if request.POST['post'] == 'yes':
            try:
                sup.deleteMail(email_id)
                sup.logout()
            except Exception as ex:
                message = u'Delete message %s from %s failed: ' % (m_email.getSubject(), m_email.getDate())
                message += ex.__unicode__()
                return render_to_response('listletter/maildelete.html', {
                    'email':m_email,
                    'email_name':m_email.getSubject(),
                    'email_deleted': 'False',
                    'isMails':True,
                    'message': message,
                    'error':'True'
                    })
            return render_to_response('listletter/maildelete.html', {
                'email':m_email,
                'email_name':m_email.getSubject(),
                'email_deleted': 'True',
                'isMails':True,
                })
    except Exception as e:
        pass
    
    return render_to_response('listletter/maildelete.html', {
        'email': m_email,
        'email_name':m_email.getSubject(),
        'email_deleted': 'False',
        'isMails':True,
        })
コード例 #4
0
def sendmail(request, email_id):
    userName = request.user.username
    listLetterSender = ListletterSender.objects.filter(
        user__username=request.user.username)[0]

    selected_email = email_id
    selected_groups = None
    available_groups = EmailTargetGroup.objects.filter(
        user__user__username=request.user.username)

    mode = ''
    sup = InboxSupplier()
    sup.login(mail_host, listLetterSender.mailUsername,
              listLetterSender.mailPassword)
    m_email = sup.getEmail(int(email_id))
    sup.logout()

    try:
        was_send = request.POST['_send']
        mode = 'send'
    except:
        mode = 'approve'

    if mode == 'send':
        mode = 'send'
        sender = SmtpSender()
        sender.login(mail_host, listLetterSender.mailUsername,
                     listLetterSender.mailPassword)
        selected_groups = Helper.getGroups(request)
        selected_email_targets = Helper.getUsersOfGroups(
            selected_groups, listLetterSender)

        mime_mail = Parser().parsestr(m_email.body)
        time1 = time.time()
        lla = sender.sendMail(mime_mail, selected_email_targets,
                              listLetterSender)
        sender.logout()
        time2 = time.time()
        seconds_elapsed = (time2 - time1)

        return render_to_response(
            'listletter/approve.html', {
                'email': m_email,
                'selected_groups': selected_groups,
                'action': mode,
                'err_cnt': len(lla.senderror_set.all()),
                'suc_cnt': len(lla.sendaction_set.all()),
                'seconds_elapsed': seconds_elapsed,
                'listletteraction': lla,
                'isMails': True,
            })

    else:
        return render_to_response(
            'listletter/approve.html', {
                'email': m_email,
                'available_groups': available_groups,
                'action': mode,
                'isMails': True,
                'email_sender': listLetterSender.emailAddress,
            })