Ejemplo n.º 1
0
    def handle(self, *args, **options):

        verbosity = options.get("verbosity", 0)
        add_email = options.get("add", False)
        delete_email = options.get("delete", False)
        list_emails = options.get("list", False)

        access_key_id = getattr(settings, "AWS_ACCESS_KEY_ID", None)
        access_key = getattr(settings, "AWS_SECRET_ACCESS_KEY", None)

        connection = SESConnection(aws_access_key_id=access_key_id, aws_secret_access_key=access_key)

        if add_email:
            if verbosity != "0":
                print "Adding email: %s" % add_email
            connection.verify_email_address(add_email)
        elif delete_email:
            if verbosity != "0":
                print "Removing email: %s" % delete_email
            connection.delete_verified_email_address(delete_email)
        elif list_emails:
            if verbosity != "0":
                print "Fetching list of verified emails:"
            response = connection.list_verified_email_addresses()
            emails = response["ListVerifiedEmailAddressesResponse"]["ListVerifiedEmailAddressesResult"][
                "VerifiedEmailAddresses"
            ]
            for email in emails:
                print email
Ejemplo n.º 2
0
    def handle(self, *args, **options):

        verbosity = options.get('verbosity', 0)
        add_email = options.get('add', False)
        delete_email = options.get('delete', False)
        list_emails = options.get('list', False)

        access_key_id = settings.ACCESS_KEY
        access_key = settings.SECRET_KEY
        region = RegionInfo(
            name=settings.AWS_SES_REGION_NAME,
            endpoint=settings.AWS_SES_REGION_ENDPOINT)

        connection = SESConnection(
                aws_access_key_id=access_key_id,
                aws_secret_access_key=access_key,
                region=region)

        if add_email:
            if verbosity != '0':
                print "Adding email: %s" % add_email
            connection.verify_email_address(add_email)
        elif delete_email:
            if verbosity != '0':
                print "Removing email: %s" % delete_email
            connection.delete_verified_email_address(delete_email)
        elif list_emails:
            if verbosity != '0':
                print "Fetching list of verified emails:"
            response = connection.list_verified_email_addresses()
            emails = response['ListVerifiedEmailAddressesResponse'][
                'ListVerifiedEmailAddressesResult']['VerifiedEmailAddresses']
            for email in emails:
                print email
Ejemplo n.º 3
0
 def handle(self, *args, **options):
     
     verbosity = options.get('verbosity', 0)
     add_email = options.get('add', False)
     delete_email = options.get('delete', False)
     list_emails = options.get('list', False)
     
     access_key_id = getattr(settings, 'AWS_ACCESS_KEY_ID', None)
     access_key = getattr(settings, 'AWS_SECRET_ACCESS_KEY', None)
     api_endpoint = getattr(settings, 'AWS_SES_API_HOST',
                                  SESConnection.DefaultHost)
     
     connection = SESConnection(
             aws_access_key_id=access_key_id,
             aws_secret_access_key=access_key,
             host=api_endpoint,
         )
     
     if add_email:
         if verbosity != '0':
             print "Adding email: %s"  % add_email
         connection.verify_email_address(add_email)
     elif delete_email:
         if verbosity != '0':
             print "Removing email: %s" % delete_email
         connection.delete_verified_email_address(delete_email)
     elif list_emails:
         if verbosity != '0':
             print "Fetching list of verified emails:"
         response = connection.list_verified_email_addresses()
         emails = response['ListVerifiedEmailAddressesResponse']['ListVerifiedEmailAddressesResult']['VerifiedEmailAddresses']
         for email in emails:
             print email
Ejemplo n.º 4
0
 def handle(self, *args, **options):
     
     verbosity = options.get('verbosity', 0)
     add_email = options.get('add', False)
     delete_email = options.get('delete', False)
     list_emails = options.get('list', False)
     
     access_key_id = getattr(settings, 'AWS_ACCESS_KEY_ID', None)
     access_key = getattr(settings, 'AWS_SECRET_ACCESS_KEY', None)
     api_endpoint = getattr(settings, 'AWS_SES_API_HOST',
                                  '%s.%s' % (
                                     SESConnection.DefaultRegionName,
                                     SESConnection.DefaultRegionEndpoint))
     
     connection = SESConnection(
             aws_access_key_id=access_key_id,
             aws_secret_access_key=access_key,
             host=api_endpoint,
         )
     
     if add_email:
         if verbosity != '0':
             print "Adding email: %s"  % add_email
         connection.verify_email_address(add_email)
     elif delete_email:
         if verbosity != '0':
             print "Removing email: %s" % delete_email
         connection.delete_verified_email_address(delete_email)
     elif list_emails:
         if verbosity != '0':
             print "Fetching list of verified emails:"
         response = connection.list_verified_email_addresses()
         emails = response['ListVerifiedEmailAddressesResponse']['ListVerifiedEmailAddressesResult']['VerifiedEmailAddresses']
         for email in emails:
             print email
Ejemplo n.º 5
0
    def handle(self, *args, **options):

        verbosity = options.get('verbosity', 0)
        add_email = options.get('add', False)
        delete_email = options.get('delete', False)
        list_emails = options.get('list', False)

        access_key_id = settings.ACCESS_KEY
        access_key = settings.SECRET_KEY
        region = RegionInfo(
            name=settings.AWS_SES_REGION_NAME,
            endpoint=settings.AWS_SES_REGION_ENDPOINT)

        connection = SESConnection(
                aws_access_key_id=access_key_id,
                aws_secret_access_key=access_key,
                region=region)

        if add_email:
            if verbosity != '0':
                print "Adding email: %s" % add_email
            connection.verify_email_address(add_email)
        elif delete_email:
            if verbosity != '0':
                print "Removing email: %s" % delete_email
            connection.delete_verified_email_address(delete_email)
        elif list_emails:
            if verbosity != '0':
                print "Fetching list of verified emails:"
            response = connection.list_verified_email_addresses()
            emails = response['ListVerifiedEmailAddressesResponse'][
                'ListVerifiedEmailAddressesResult']['VerifiedEmailAddresses']
            for email in emails:
                print email
Ejemplo n.º 6
0
    def handle(self, *args, **options):

        verbosity = options.get('verbosity', 0)
        add_email = options.get('add', False)
        delete_email = options.get('delete', False)
        list_emails = options.get('list', False)

        access_key_id = settings.ACCESS_KEY
        access_key = settings.SECRET_KEY
        region = RegionInfo(
            name=settings.AWS_SES_REGION_NAME,
            endpoint=settings.AWS_SES_REGION_ENDPOINT)
        proxy = settings.AWS_SES_PROXY
        proxy_port = settings.AWS_SES_PROXY_PORT
        proxy_user = settings.AWS_SES_PROXY_USER
        proxy_pass = settings.AWS_SES_PROXY_PASS


        connection = SESConnection(
                aws_access_key_id=access_key_id,
                aws_secret_access_key=access_key,
                region=region,
                proxy=proxy,
                proxy_port=proxy_port,
                proxy_user=proxy_user,
                proxy_pass=proxy_pass,
        )

        if add_email:
            if verbosity != '0':
                print("Adding email: " + add_email)
            connection.verify_email_address(add_email)
        elif delete_email:
            if verbosity != '0':
                print("Removing email: " + delete_email)
            connection.delete_verified_email_address(delete_email)
        elif list_emails:
            if verbosity != '0':
                print("Fetching list of verified emails:")
            response = connection.list_verified_email_addresses()
            emails = response['ListVerifiedEmailAddressesResponse'][
                'ListVerifiedEmailAddressesResult']['VerifiedEmailAddresses']
            for email in emails:
                print(email)
Ejemplo n.º 7
0
def mailsender(request):
    
    mail = request.FILES[u"file"].read()
    to = request.GET["to"]
    
    #split headers
    i = mail.find("\n\n")
    headers, mail = mail[:i], mail[i:]
    headers = headers.split("\n")
    allowed = {"MIME-Version", "Message-ID", "In-Reply-To", "Content-Type", 
               "Date", "Subject", "From", "To", "Bcc", "Cc", "References"}
    
    from_ = None
    
    h = []
    i=0
    while i<len(headers):
        add = False
        header = headers[i][:headers[i].find(":")]
        if header in allowed:
            add = True
        if header == "From":
            from_ = headers[i][headers[i].find(":")+1:].strip()
            
        while True:
            if add: 
                h.append(headers[i])
            i += 1
            if i>=len(headers) or headers[i][0] not in " \t":
                break
            
    mail = "\n".join(h) + mail
    
    #find from email
    i = from_.find("<")
    if i != -1:
        from_ = from_[i+1:]
        from_ = from_[:from_.find(">")]
    
    #logger.info("headers: %s", str(headers))
    #logger.info("h: %s", str(h))
    
    logger.info("Mail from %s to %s recieved", from_, to)
    # Only allow sending from altekamereren domains and registered users.
    if not from_.endswith("@altekamereren.org") \
            and not from_.endswith("@altekamereren.com") \
            and User.objects.filter(email=from_).exists():
        logger.info("Sender not accepted.")
        return HttpResponse(status=403)
    
    to = to.replace(u"flojt", u"flöjt")
    reciever = to.split("@")[0]
    if reciever in ak.sections:
        user_emails = [user.email for user in User.objects.filter(
            instrument__in=ak.section_to_short_instruments[reciever], 
            is_active=True)]

        

        logger.info("Sending to section %s: %s", to, str(user_emails))

    elif reciever == u"infolistan":
        reciever = [user.email for user in User.objects.filter(is_active=True)]
        logger.info("Sending to infolistan: %s", str(reciever))
    else:
        logger.info("List not accepted.")
        return HttpResponse(status=400)
    
    from django.conf import settings
    from boto.ses import SESConnection
    from boto.exception import BotoServerError
    
    access_key_id = getattr(settings, 'AWS_ACCESS_KEY_ID', None)
    access_key = getattr(settings, 'AWS_SECRET_ACCESS_KEY', None)
    api_endpoint = getattr(settings, 'AWS_SES_API_HOST',
                                     SESConnection.DefaultHost)
    connection = SESConnection(
                aws_access_key_id=access_key_id,
                aws_secret_access_key=access_key,
                host=api_endpoint,
    )
    
    if not user_emails:
        return HttpResponse(status=400)

    try:
        connection.send_raw_email(mail, settings.ADMINS[0][1], user_emails)
    except BotoServerError as e:
        i = e.body.find("<Message>")
        message = e.body[i+len("<Message>"):]
        message = message[:message.find("</Message>")]
        
        if message == "Email address is not verified.":
            if MailVerificationSent.objects.filter(email=from_, 
                    sent__gte=datetime.datetime.now() - datetime.timedelta(days=1)
                        ).exists():
                connection.verify_email_address(from_)
                logger.error("Sending verify mail to: %s", from_)
                MailVerificationSent(email=from_).save()
            else:
                logger.error("Verify mail already sent today: %s", from_)
            return HttpResponse(status=444)
        else:
            raise

    
    return HttpResponse()
Ejemplo n.º 8
0
def mailsender(request):

    mail = request.FILES[u"file"].read()
    to = request.GET["to"]

    # split headers
    i = mail.find("\n\n")
    headers, mail = mail[:i], mail[i:]
    headers = headers.split("\n")
    allowed = {
        "MIME-Version",
        "Message-ID",
        "In-Reply-To",
        "Content-Type",
        "Date",
        "Subject",
        "From",
        "To",
        "Bcc",
        "Cc",
        "References",
    }

    from_ = None

    h = []
    i = 0
    while i < len(headers):
        add = False
        header = headers[i][: headers[i].find(":")]
        if header in allowed:
            add = True
        if header == "From":
            from_ = headers[i][headers[i].find(":") + 1 :].strip()

        while True:
            if add:
                h.append(headers[i])
            i += 1
            if i >= len(headers) or headers[i][0] not in " \t":
                break

    mail = "\n".join(h) + mail

    # find from email
    i = from_.find("<")
    if i != -1:
        from_ = from_[i + 1 :]
        from_ = from_[: from_.find(">")]

    # logger.info("headers: %s", str(headers))
    # logger.info("h: %s", str(h))

    logger.info("Mail from %s to %s recieved", from_, to)
    # Only allow sending from altekamereren domains and registered users.
    if (
        not from_.endswith("@altekamereren.org")
        and not from_.endswith("@altekamereren.com")
        and User.objects.filter(email=from_).exists()
    ):
        logger.info("Sender not accepted.")
        return HttpResponse(status=403)

    to = to.replace(u"flojt", u"flöjt")
    reciever = to.split("@")[0]
    if reciever in ak.sections:
        user_emails = [
            user.email
            for user in User.objects.filter(instrument__in=ak.section_to_short_instruments[reciever], is_active=True)
        ]

        logger.info("Sending to section %s: %s", to, str(user_emails))

    elif reciever == u"infolistan":
        reciever = [user.email for user in User.objects.filter(is_active=True)]
        logger.info("Sending to infolistan: %s", str(reciever))
    else:
        logger.info("List not accepted.")
        return HttpResponse(status=400)

    from django.conf import settings
    from boto.ses import SESConnection
    from boto.exception import BotoServerError

    access_key_id = getattr(settings, "AWS_ACCESS_KEY_ID", None)
    access_key = getattr(settings, "AWS_SECRET_ACCESS_KEY", None)
    api_endpoint = getattr(settings, "AWS_SES_API_HOST", SESConnection.DefaultHost)
    connection = SESConnection(aws_access_key_id=access_key_id, aws_secret_access_key=access_key, host=api_endpoint)

    if not user_emails:
        return HttpResponse(status=400)

    try:
        connection.send_raw_email(mail, settings.ADMINS[0][1], user_emails)
    except BotoServerError as e:
        i = e.body.find("<Message>")
        message = e.body[i + len("<Message>") :]
        message = message[: message.find("</Message>")]

        if message == "Email address is not verified.":
            if MailVerificationSent.objects.filter(
                email=from_, sent__gte=datetime.datetime.now() - datetime.timedelta(days=1)
            ).exists():
                connection.verify_email_address(from_)
                logger.error("Sending verify mail to: %s", from_)
                MailVerificationSent(email=from_).save()
            else:
                logger.error("Verify mail already sent today: %s", from_)
            return HttpResponse(status=444)
        else:
            raise

    return HttpResponse()