Beispiel #1
0
def send_autoreply(sender, mailbox, armessage):
    if armessage.fromdate > timezone.now():
        return
    if armessage.untildate is not None \
            and armessage.untildate < timezone.now():
        armessage.enabled = False
        armessage.save()
        return

    try:
        lastar = ARhistoric.objects.get(armessage=armessage.id, sender=sender)
        timeout = parameters.get_admin("AUTOREPLIES_TIMEOUT",
                                       app="postfix_autoreply")
        delta = datetime.timedelta(seconds=int(timeout))
        now = timezone.make_aware(datetime.datetime.now(),
                                  timezone.get_default_timezone())
        if lastar.last_sent + delta > now:
            sys.exit(0)
    except ARhistoric.DoesNotExist:
        lastar = ARhistoric()
        lastar.armessage = armessage
        lastar.sender = sender

    sendmail_simple(mailbox.user.encoded_address, sender, armessage.subject,
                    armessage.content.encode('utf-8'))

    lastar.last_sent = datetime.datetime.now()
    lastar.save()
Beispiel #2
0
def send_autoreply(sender, mailbox, armessage):
    if armessage.fromdate > timezone.now():
        return
    if armessage.untildate is not None \
            and armessage.untildate < timezone.now():
        armessage.enabled = False
        armessage.save()
        return

    try:
        lastar = ARhistoric.objects.get(armessage=armessage.id, sender=sender)
        PostfixAutoreply().load()
        timeout = parameters.get_admin("AUTOREPLIES_TIMEOUT",
                                       app="postfix_autoreply")
        delta = datetime.timedelta(seconds=int(timeout))
        now = timezone.make_aware(datetime.datetime.now(),
                                  timezone.get_default_timezone())
        if lastar.last_sent + delta > now:
            sys.exit(0)
    except ARhistoric.DoesNotExist:
        lastar = ARhistoric()
        lastar.armessage = armessage
        lastar.sender = sender

    sendmail_simple(mailbox.user.encoded_address, sender, armessage.subject,
                    armessage.content.encode('utf-8'))

    lastar.last_sent = datetime.datetime.now()
    lastar.save()
Beispiel #3
0
    def check_valid_mx(self, domain, mx_list, **options):
        """Check that domain's MX record exist.

        If `valid_mx` is provided, retrieved MX records must be
        contained in it.
        """
        alerts = []
        check = False
        mxs = [(mx, ipaddress.ip_address(u"%s" % mx.address))
               for mx in mx_list]
        valid_mxs = self.valid_mxs
        if not mxs:
            alerts.append(_("Domain {} has no MX record").format(domain))
        elif valid_mxs:
            for subnet in valid_mxs:
                for mx, addr in mxs:
                    if addr in subnet:
                        mx.managed = check = True
                        mx.save()
            if check is False:
                mx_names = [
                    "{0.name} ({0.address})".format(mx) for mx in mx_list
                ]
                alerts.append(
                    _("MX record for domain {0} is invalid: {1}").format(
                        domain, ", ".join(mx_names)))
        if not alerts:
            return
        emails = options["email"]
        if not options["skip_admin_emails"]:
            emails.extend(
                domain.admins.exclude(email="").values_list("email",
                                                            flat=True))
        if not len(emails):
            return
        content = render_to_string(
            "admin/notifications/domain_invalid_mx.html", {
                "domain": domain,
                "alerts": alerts
            })
        subject = _("[modoboa] MX issue(s) for domain {}").format(domain.name)
        for email in emails:
            status, msg = email_utils.sendmail_simple(self.sender,
                                                      email,
                                                      subject=subject,
                                                      content=content)
            if not status:
                print(msg)
Beispiel #4
0
    def check_valid_mx(self, domain, mx_list, **options):
        """Check that domain's MX record exist.

        If `valid_mx` is provided, retrieved MX records must be
        contained in it.
        """
        alerts = []
        check = False
        mxs = [(mx, ipaddress.ip_address(u"%s" % mx.address))
               for mx in mx_list]
        valid_mxs = self.valid_mxs
        if not mxs:
            alerts.append(_("Domain {} has no MX record").format(domain))
        elif valid_mxs:
            for subnet in valid_mxs:
                for mx, addr in mxs:
                    if addr in subnet:
                        mx.managed = check = True
                        mx.save()
            if check is False:
                mx_names = [
                    "{0.name} ({0.address})".format(mx) for mx in mx_list]
                alerts.append(
                    _("MX record for domain {0} is invalid: {1}").format(
                        domain, ", ".join(mx_names))
                )
        if not alerts:
            return
        emails = options["email"]
        if not options["skip_admin_emails"]:
            emails.extend(
                domain.admins.exclude(email="").values_list("email", flat=True)
            )
        if not len(emails):
            return
        content = render_to_string(
            "admin/notifications/domain_invalid_mx.html", {
                "domain": domain, "alerts": alerts
            })
        subject = _("[modoboa] MX issue(s) for domain {}").format(
            domain.name)
        for email in emails:
            status, msg = email_utils.sendmail_simple(
                self.sender, email,
                subject=subject, content=content)
            if not status:
                print(msg)
Beispiel #5
0
 def store_dnsbl_result(self, domain, provider, results, **options):
     """Store DNSBL provider results for domain."""
     alerts = {}
     to_create = []
     for mx in results.keys():
         result = "" if not results[mx] else results[mx]
         dnsbl_result = models.DNSBLResult.objects.filter(domain=domain,
                                                          provider=provider,
                                                          mx=mx).first()
         if dnsbl_result is None:
             to_create.append(
                 models.DNSBLResult(domain=domain,
                                    provider=provider,
                                    mx=mx,
                                    status=result))
         else:
             if not dnsbl_result.status and result:
                 if domain not in alerts:
                     alerts[domain] = []
                 alerts[domain].append((provider, mx))
             dnsbl_result.status = result
             dnsbl_result.save()
     models.DNSBLResult.objects.bulk_create(to_create)
     if not alerts:
         return
     emails = options["email"]
     if not options["skip_admin_emails"]:
         emails.extend(
             domain.admins.exclude(email="").values_list("email",
                                                         flat=True))
     if not len(emails):
         return
     content = render_to_string("admin/notifications/domain_in_dnsbl.html",
                                {
                                    "domain": domain,
                                    "alerts": alerts
                                })
     subject = _("[modoboa] DNSBL issue(s) for domain {}").format(
         domain.name)
     for email in emails:
         status, msg = email_utils.sendmail_simple(self.sender,
                                                   email,
                                                   subject=subject,
                                                   content=content)
         if not status:
             print(msg)
Beispiel #6
0
 def store_dnsbl_result(self, domain, provider, results, **options):
     """Store DNSBL provider results for domain."""
     alerts = {}
     to_create = []
     for mx in results.keys():
         result = "" if not results[mx] else results[mx]
         dnsbl_result = models.DNSBLResult.objects.filter(
             domain=domain, provider=provider, mx=mx).first()
         if dnsbl_result is None:
             to_create.append(
                 models.DNSBLResult(
                     domain=domain, provider=provider, mx=mx,
                     status=result)
             )
         else:
             if not dnsbl_result.status and result:
                 if domain not in alerts:
                     alerts[domain] = []
                 alerts[domain].append((provider, mx))
             dnsbl_result.status = result
             dnsbl_result.save()
     models.DNSBLResult.objects.bulk_create(to_create)
     if not alerts:
         return
     emails = options["email"]
     if not options["skip_admin_emails"]:
         emails.extend(
             domain.admins.exclude(email="").values_list("email", flat=True)
         )
     if not len(emails):
         return
     content = render_to_string(
         "admin/notifications/domain_in_dnsbl.html", {
             "domain": domain, "alerts": alerts
         })
     subject = _("[modoboa] DNSBL issue(s) for domain {}").format(
         domain.name)
     for email in emails:
         status, msg = email_utils.sendmail_simple(
             self.sender, email,
             subject=subject, content=content)
         if not status:
             print(msg)
Beispiel #7
0
 def send_pr_notification(self, rcpt, reqs):
     if self.options["verbose"]:
         print "Sending notification to %s" % rcpt
     total = reqs.count()
     reqs = reqs.all()[:10]
     content = render_to_string(
         "amavis/notifications/pending_requests.html",
         dict(total=total,
              requests=reqs,
              baseurl=self.baseurl,
              listingurl=self.listingurl))
     status, msg = sendmail_simple(
         self.sender,
         rcpt,
         subject=_("[modoboa] Pending release requests"),
         content=content,
         server=self.options["smtp_host"],
         port=self.options["smtp_port"])
     if not status:
         print msg
Beispiel #8
0
 def send_pr_notification(self, rcpt, reqs):
     if self.options["verbose"]:
         print "Sending notification to %s" % rcpt
     total = reqs.count()
     reqs = reqs.all()[:10]
     content = render_to_string(
         "modoboa_amavis/notifications/pending_requests.html", dict(
             total=total, requests=reqs,
             baseurl=self.baseurl, listingurl=self.listingurl
         )
     )
     status, msg = sendmail_simple(
         self.sender, rcpt,
         subject=_("[modoboa] Pending release requests"),
         content=content,
         server=self.options["smtp_host"],
         port=self.options["smtp_port"]
     )
     if not status:
         print msg
Beispiel #9
0
def send_spam(request):
    status, error = sendmail_simple(
        "*****@*****.**", request.user.username, content="""
This is the GTUBE, the
        Generic
        Test for
        Unsolicited
        Bulk
        Email

If your spam filter supports it, the GTUBE provides a test by which you
can verify that the filter is installed correctly and is detecting incoming
spam. You can send yourself a test mail containing the following string of
characters (in upper case and with no white spaces and line breaks):

XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X

You should send this test mail from an account outside of your network.
""")
    if status:
        return render_to_json_response(_("Message sent"))
    return render_to_json_response(respmsg=error, status=500)
Beispiel #10
0
 def store_domain_result(self, domain, provider, results):
     """Store provider results for domain."""
     alerts = {}
     to_create = []
     for ip in results.keys():
         result = "" if not results[ip] else results[ip]
         dnsbl_result = models.DNSBLResult.objects.filter(
             domain=domain, provider=provider, mx=ip).first()
         if dnsbl_result is None:
             to_create.append(
                 models.DNSBLResult(
                     domain=domain, provider=provider, mx=ip,
                     status=result)
             )
         else:
             if not dnsbl_result.status and result:
                 if domain not in alerts:
                     alerts[domain] = []
                 alerts[domain].append((provider, ip))
             dnsbl_result.status = result
             dnsbl_result.save()
     models.DNSBLResult.objects.bulk_create(to_create)
     if not alerts:
         return
     content = render_to_string(
         "admin/notifications/domain_in_dnsbl.html", {
             "domain": domain, "alerts": alerts
         })
     subject = _("[modoboa] DNSBL issue(s) for domain {}").format(
         domain.name)
     for admin in domain.admins:
         if not admin.email:
             continue
         status, msg = email_utils.sendmail_simple(
             self.sender, admin.email,
             domainsubject=subject, content=content)
         if not status:
             print msg