-1
            try:
            if not self.check_smtp_connected("main", self.sender_addr):
                self.close("main", self.sender_addr)
                if not self.connect("main", self.sender_addr):
                    self.last_error = "req_id:%d,connect to %s main failed" % (mail_id, self.name)
                    raise Exception("req_id:%d,connect to %s main failed" % (mail_id, self.name))
            sender_addr = parseaddr(self.msg['From'])[1]
            recv_addr   = parseaddr(self.msg['To'])[1]
            self.smtp_conns[self.sender_addr].sendmail(self.msg['From'], self.msg['To'], self.msg.as_string())
        except Exception as e:
            glogger.warning("req_id:%d,send mail by %s failed, error: %s" % (mail_id, self.name, str(e)))
        else:
            sent_succ = True
            break

check_smtp_connected use noop()[0] to check connection to smtp server.

the first time I get : req_id:7066283,send mail by tx_smtp failed, error: timed out

so the exception is time out and then I use check_smtp_connected to check the connection, it's broken.

the second time I get: req_id:7066283,send mail by tx_smtp failed, error: (250, 'Ok') so the exception is (250, 'Ok')

I read source code of sendmail, but can't find the branch that will raise this exception.

so I'm heavily puzzled. and the result is my mailbox get two mail

  • 1
    Please post some code that can fully demonstrate the problem and write a proper error description with the full traceback. – Klaus D. Nov 07 '17 at 09:28

1 Answers1

0

I solve this problem,because I set the smtplib argument 'timeout=3',and the mail is too big, so the first time I get "timed out". I guess the second time I get the reply of the first time,because I really get this mail twice ,but not proved. and I set timeout larger,and everything goes okay!