Beispiel #1
0
 def sendmail(self, attachment, aname, to, subject, text, log):
     while time.time() - self.last_send_time <= self.rate_limit:
         time.sleep(1)
     try:
         opts = email_config().parse()
         from_ = opts.from_
         if not from_:
             from_ = 'calibre <calibre@' + socket.getfqdn() + '>'
         with lopen(attachment, 'rb') as f:
             msg = compose_mail(from_, to, text, subject, f, aname)
         efrom, eto = map(extract_email_address, (from_, to))
         eto = [eto]
         sendmail(msg,
                  efrom,
                  eto,
                  localhost=None,
                  verbose=1,
                  relay=opts.relay_host,
                  username=opts.relay_username,
                  password=unhexlify(opts.relay_password),
                  port=opts.relay_port,
                  encryption=opts.encryption,
                  debug_output=log.debug)
     finally:
         self.last_send_time = time.time()
Beispiel #2
0
 def sendmail(self, attachment, aname, to, subject, text, log):
     logged = False
     while time.time() - self.last_send_time <= self.rate_limit:
         if not logged and self.rate_limit > 0:
             log('Waiting %s seconds before sending, to avoid being marked as spam.\nYou can control this delay via Preferences->Tweaks' % self.rate_limit)
             logged = True
         time.sleep(1)
     try:
         opts = email_config().parse()
         from_ = opts.from_
         if not from_:
             from_ = 'calibre <calibre@'+socket.getfqdn()+'>'
         with lopen(attachment, 'rb') as f:
             msg = compose_mail(from_, to, text, subject, f, aname)
         efrom = extract_email_address(from_)
         eto = []
         for x in to.split(','):
             eto.append(extract_email_address(x.strip()))
         sendmail(msg, efrom, eto, localhost=None,
                     verbose=1,
                     relay=opts.relay_host,
                     username=opts.relay_username,
                     password=unhexlify(opts.relay_password).decode('utf-8'), port=opts.relay_port,
                     encryption=opts.encryption,
                     debug_output=log.debug)
     finally:
         self.last_send_time = time.time()
Beispiel #3
0
 def sendmail(self, attachment, aname, to, subject, text, log):
     logged = False
     while time.time() - self.last_send_time <= self.rate_limit:
         if not logged and self.rate_limit > 0:
             log('Waiting %s seconds before sending, to avoid being marked as spam.\nYou can control this delay via Preferences->Tweaks'
                 % self.rate_limit)
             logged = True
         time.sleep(1)
     try:
         opts = email_config().parse()
         from_ = opts.from_
         if not from_:
             from_ = 'calibre <calibre@' + socket.getfqdn() + '>'
         with lopen(attachment, 'rb') as f:
             msg = compose_mail(from_, to, text, subject, f, aname)
         efrom = extract_email_address(from_)
         eto = []
         for x in to.split(','):
             eto.append(extract_email_address(x.strip()))
         sendmail(msg,
                  efrom,
                  eto,
                  localhost=None,
                  verbose=1,
                  relay=opts.relay_host,
                  username=opts.relay_username,
                  password=unhexlify(opts.relay_password).decode('utf-8'),
                  port=opts.relay_port,
                  encryption=opts.encryption,
                  debug_output=log.debug)
     finally:
         self.last_send_time = time.time()
Beispiel #4
0
    def sendmail(self, attachment, aname, to, subject, text, log):
        logged = False
        while time.time() - self.last_send_time <= self.rate_limit:
            if not logged and self.rate_limit > 0:
                log('Waiting %s seconds before sending, to avoid being marked as spam.\nYou can control this delay via Preferences->Tweaks'
                    % self.rate_limit)
                logged = True
            time.sleep(1)
        try:
            opts = email_config().parse()
            from_ = opts.from_
            if not from_:
                from_ = 'calibre <calibre@' + socket.getfqdn() + '>'
            with lopen(attachment, 'rb') as f:
                msg = compose_mail(from_, to, text, subject, f, aname)
            efrom = extract_email_address(from_)
            eto = []
            for x in to.split(','):
                eto.append(extract_email_address(x.strip()))

            def safe_debug(*args, **kwargs):
                try:
                    return log.debug(*args, **kwargs)
                except Exception:
                    pass

            relay = opts.relay_host
            if relay and relay == 'smtp.live.com':
                # Microsoft changed the SMTP server
                relay = 'smtp-mail.outlook.com'

            sendmail(msg,
                     efrom,
                     eto,
                     localhost=None,
                     verbose=1,
                     relay=relay,
                     username=opts.relay_username,
                     password=from_hex_unicode(opts.relay_password),
                     port=opts.relay_port,
                     encryption=opts.encryption,
                     debug_output=safe_debug)
        finally:
            self.last_send_time = time.time()
Beispiel #5
0
 def sendmail(self, attachment, aname, to, subject, text, log):
     while time.time() - self.last_send_time <= self.rate_limit:
         time.sleep(1)
     try:
         opts = email_config().parse()
         from_ = opts.from_
         if not from_:
             from_ = 'calibre <calibre@'+socket.getfqdn()+'>'
         with lopen(attachment, 'rb') as f:
             msg = compose_mail(from_, to, text, subject, f, aname)
         efrom, eto = map(extract_email_address, (from_, to))
         eto = [eto]
         sendmail(msg, efrom, eto, localhost=None,
                     verbose=1,
                     relay=opts.relay_host,
                     username=opts.relay_username,
                     password=unhexlify(opts.relay_password), port=opts.relay_port,
                     encryption=opts.encryption,
                     debug_output=log.debug)
     finally:
         self.last_send_time = time.time()