예제 #1
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,
            })
예제 #2
0
def upload_contacts(request):
    isContacts=True
    message = ''
    failed = []
    imported = 0
    llSender = ListletterSender.objects.filter(user__username=request.user.username)[0]
    
    if request.method == 'POST':
        action = 'done'        
        form = UploadFileForm(request.POST, request.FILES, llSender)
        if form.is_valid():
            imported, failed = Helper.importContacts(request.FILES['file'], llSender)
            message = '%d contacts were imported successfully, the import of %d contacts failed.' % (imported, len(failed))
        else:
            message = 'not valid'
    else:
        action = 'upload'
        form = UploadFileForm()
        
    return render_to_response('listletter/contact_upload.html', {
        'form': form,
        'action':action,
        'message':message,
        'failed':failed,
        'numfailed':len(failed),
        'isContacts':isContacts
        })
예제 #3
0
def upload_contacts(request):
    isContacts = True
    message = ''
    failed = []
    imported = 0
    llSender = ListletterSender.objects.filter(
        user__username=request.user.username)[0]

    if request.method == 'POST':
        action = 'done'
        form = UploadFileForm(request.POST, request.FILES, llSender)
        if form.is_valid():
            imported, failed = Helper.importContacts(request.FILES['file'],
                                                     llSender)
            message = '%d contacts were imported successfully, the import of %d contacts failed.' % (
                imported, len(failed))
        else:
            message = 'not valid'
    else:
        action = 'upload'
        form = UploadFileForm()

    return render_to_response(
        'listletter/contact_upload.html', {
            'form': form,
            'action': action,
            'message': message,
            'failed': failed,
            'numfailed': len(failed),
            'isContacts': isContacts
        })
예제 #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,
            })