def getDNSNames(self, found_names):
     """
     Do a few DNS checks to extract other names that we should be monitoring.  Wrap all
     of this in try/except clauses in case there are any problems with the DNS results.
     """
     logging.debug("Getting DNS names for %s" % self.name)
     
     # Grab their authoritative DNS servers
     try:
         r = DNS.Request(name=self.name, qtype='NS').req()
         for a in r.answers:
             name = a['data']
             if not found_names.has_key(name): found_names[name] = set()
             found_names[name].add('tcp.dns')
             found_names[name].add('udp.dns')
     except:
         logging.error("Problems looking up root nameservers for %s: %s" % (self.name, traceback.format_exc()))
         
     # Grab their domain's MX servers
     try:
         for (priority, name) in mxlookup(self.name):
             if not found_names.has_key(name): found_names[name] = set()
             found_names[name].add('tcp.smtp_mx')
     except:
         logging.error("Problems looking up MX servers for %s: %s" % (self.name, traceback.format_exc()))
Exemplo n.º 2
0
 def validatePython(self, value, state):
     if not value:
         raise InvalidField(
             self.message('empty', 'Please enter an email address'),
             value, state)
     value = string.strip(value)
     splitted = string.split(value, '@', 1)
     if not len(splitted) == 2:
         raise InvalidField(
             self.message('noAt', 'An email address must contain an @'),
             value, state)
     if not self.usernameRE.search(splitted[0]):
         raise InvalidField(
             self.message('badUsername', 'The username portion of the email address is invalid (the portion before the @: %(username)s)') % {"username": htmlEncode(splitted[0])},
             value, state)
     if not self.domainRE.search(splitted[1]):
         raise InvalidField(
             self.message('badDomain', 'The domain portion of the email address is invalid (the portion after the @: %(domain)s)') % {"domain": htmlEncode(splitted[1])},
             value, state)
     if self.resolveDomain:
         domains = mxlookup(splitted[1])
         if not domains:
             raise InvalidField(
                 self.message('domainDoesNotExist', 'The domain of the email address does not exist (the portion after the @: %(domain)s)') % {"domain": splitted[1]},
                 value, state)
Exemplo n.º 3
0
if len(argv) != 4 and len(argv) != 5:
  print("Usage : " + argv[0] +" FROM TO SUBJECT [MESSAGE]")
  print(" FROM is the email address to send from")
  print(" TO is the email address to send to")
  print(" SUBJECT is the email's subject")
  print(" MESSAGE is the email's message. If not specified, it is read from stdin.")
  print("\nThis program is (c) Jan Dlabal, 2011, and is available under the terms of the GNU GPL v3 License.")
else:
  if len(argv) == 5:
    msg = MIMEText(argv[4])
  else:
    msg = MIMEText(stdin.read())
  msg['Subject'] = argv[3]
  msg['To'] = argv[2]
  msg['From'] = argv[1]
  try:
    server = mxlookup(argv[2].split('@')[1])[0][1]
  except:
    print("Error : Could not get an MX record.")
    exit(1)
  print("Connecting to " + server)
  s = smtplib.SMTP(server)
  d = s.sendmail(argv[1], [argv[2]], msg.as_string())
  if len(d) == 0:
    print("Email sent successfully")
  else:
    print("Error occured while sending : " + repr(d))
  s.quit()
  exit(0)

Exemplo n.º 4
0
    print(" TO is the email address to send to")
    print(" SUBJECT is the email's subject")
    print(
        " MESSAGE is the email's message. If not specified, it is read from stdin."
    )
    print(
        "\nThis program is (c) Jan Dlabal, 2011, and is available under the terms of the GNU GPL v3 License."
    )
else:
    if len(argv) == 5:
        msg = MIMEText(argv[4])
    else:
        msg = MIMEText(stdin.read())
    msg['Subject'] = argv[3]
    msg['To'] = argv[2]
    msg['From'] = argv[1]
    try:
        server = mxlookup(argv[2].split('@')[1])[0][1]
    except:
        print("Error : Could not get an MX record.")
        exit(1)
    print("Connecting to " + server)
    s = smtplib.SMTP(server)
    d = s.sendmail(argv[1], [argv[2]], msg.as_string())
    if len(d) == 0:
        print("Email sent successfully")
    else:
        print("Error occured while sending : " + repr(d))
    s.quit()
    exit(0)