2007年12月13日 星期四 08:59
Romit,您好!
你这里的异常捕获用的
try:
except xxx:
except xxx
这样肯定有漏掉的,要么你最后再加一个 except,要么用这样的
try:
except Exception, e:
======= 2007-12-12 09:52:26 您在来信中写道:=======
>确实是反垃圾邮件的问题,该企业会在月末向员工发送业绩、工资等信息,所以发
>送邮件量会比较大,我想在邮件服务器禁止发送后,程序自动等待10分钟后重试,
>但是每次SMTP服务器拒绝以后,随后会自动断开连接,你帮忙看一下程序存在什么
>问题。
>for a in mbl:
>
>subject=self.mngCltXML.get_widget('entry8').get_text().encode('gb2312')
>
>text=self.mngCltXML.get_widget('textview1').get_buffer().get_text(self.mngCltXML.get_widget('textview1').get_buffer().get_start_iter(),self.mngCltXML.get_widget('textview1').get_buffer().get_end_iter()).encode('gb2312')
> msg=MIMEText(text,_subtype='plain',_charset='GB2312')
>
> msg['Subject']=subject
> msg['From']=conf['user']
> msg['To']=str(a)+'@sx.133165.com'
>
> try:
> server=smtplib.SMTP(conf['host'],conf['port'])
> server.set_debuglevel(0)
> except smtplib.SMTPException:
>
>cid_except=self.mngCltXML.get_widget('statusbar1').get_context_id('Base
>exception class for all exceptions raised by this module.')
>
>self.mngCltXML.get_widget('statusbar1').push(cid_except,u'请更换信箱,服
>务器拒绝')
> time.sleep(50)
> self.mngCltXML.get_widget('statusbar1').pop(cid_except)
> except smtplib.SMTPServerDisconnected:
>
>cid_sdiscn=self.mngCltXML.get_widget('statusbar1').get_context_id('Server
>disconnectiod')
>
>self.mngCltXML.get_widget('statusbar1').pusb(cid_sdiscn,u'服务器连接中断')
> time.sleep(5)
> self.mngCltXML.get_widget('statusbar1').pop(cid_sdiscn)
> except smtplib.SMTPResponseException:
>
>cid_rsp=self.mngCltXML.get_widget('statusbar1').get_context_id('Base
>class for all exceptions that include an SMTP error code. These
>exceptions are generated in some instances when the SMTP server returns
>an error code. The error code is stored in the smtp_code attribute of
>the error, and the smtp_error attribute is set to the error message.')
> self.mngCltXML.get_widget('statusbar1').push(cid_rsp,u'
>服务器响应错误')
> time.sleep(5)
> self.mngCltXML.get_widget('statusbar1').pop(cid_rsp)
> except smtplib.SMTPSenderRefused:
>
>cid_srfus=self.mngCltXML.get_widget('statusbar1').get_context_id('Sender
>address refused. In addition to the attributes set by on all
>SMTPResponseException exceptions, this sets `sender\' to the string that
>the SMTP server refused.')
>
>self.mngCltXML.get_widget('statusbar1').push(cid_srfus,u'发件地址被拒绝')
> time.sleep(600)
> self.mngCltXML.get_widget('statusbar1').pop(cid_srfus)
> except smtplib.SMTPRecipientsRefused:
> #如果收件人不存在,直接跳过
> continue
> except smtplib.SMTPDataError:
>
>cid_data=self.mngCltXML.get_widget('statusbar1').get_context_id('The
>server replied with an unexpected error code (other than a refusal of a
>recipient).')
> self.mngCltXML.get_widget('statusbar1').push(cid_data,u'
>服务器返回错误')
> time.sleep(5)
> self.mngCltXML.get_widget('statusbar1').pop(cid_data)
> except smtplib.SMTPConnectError:
>
>cid_conn=self.mngCltXML.get_widget('statusbar1').get_context_id('Error
>occurred during establishment of a connection with the server.')
> self.mngCltXML.get_widget('statusbar1').push(cid_conn,u'
>与服务器连接错误,请更换信箱')
> time.sleep(50)
> self.mngCltXML.get_widget('statusbar1').pop(cid_conn)
> except smtplib.SMTPHeloError:
>
>cid_helo=self.mngCltXML.get_widget('statusbar1').get_context_id('The
>server didn\'t reply properly to the "HELO" greeting.')
> self.mngCltXML.get_widget('statusbar1').push(cid_helo,u'
>服务器未正确相应')
> time.sleep(5)
> self.mngCltXML.get_widget('statusbar1').pop(cid_helo)
>
>
> try:
> server.login(conf['user'],conf['passwd'])
> except smtplib.SMTPAuthenticationError:
>
>cid_auth=self.mngCltXML.get_widget('statusbar1').get_context_id('The
>server didn\'t accept the username/password combination.')
> self.mngCltXML.get_widget('statusbar1').push(cid_auth,u'
>用户名或者密码错误,请在SMTP 设置输入正确的用户和密码')
> time.sleep(5)
> self.mngCltXML.get_widget('statusbar1').pop(cid_auth)
> except smtplib.SMTPHeloError:
>
>cid_helo=self.mngCltXML.get_widget('statusbar1').get_context_id('The
>server didn\'t reply properly to the "HELO" greeting.')
> self.mngCltXML.get_widget('statusbar1').push(cid_helo,u'
>服务器未正确相应')
> time.sleep(5)
> self.mngCltXML.get_widget('statusbar1').pop(cid_helo)
> except smtplib.SMTPError:
>
>cid_err=self.mngCltXML.get_widget('statusbar1').get_context_id('No
>suitable authentication method was found')
> mngCltXML.get_widget('statusbar1').push(cid_err,u'验证方
>法不匹配')
> break
> self.mngCltXML.get_widget('statusbar1').pop(cid_err)
>
>
> try:
> server.sendmail(conf['user'],
>str(a[0])+'@sx.133165.com',msg.as_string())
> except smtplib.SMTPRecipientsRefused:
> #如果收件人不存在,直接跳过
> continue
> except smtplib.SMTPHeloError:
>
>cid_helo=self.mngCltXML.get_widget('statusbar1').get_context_id('The
>server didn\'t reply properly to the "HELO" greeting.')
> self.mngCltXML.get_widget('statusbar1').push(cid_helo,u'
>服务器未正确相应')
> time.sleep(5)
> self.mngCltXML.get_widget('statusbar1').pop(cid_helo)
> except smtplib.SMTPSenderRefused:
> # 发件地址被拒绝通常是由于发送大量电子邮件爱你导致,所以
>休眠一段时间后重复发送
> server.close()
> time.sleep(600)
> server=smtplib.SMTP(conf['host'],conf['port'])
> server.server.login(conf['user'],conf['passwd'])
>
> except smtplib.SMTPDataError:
>
>cid_data=self.mngCltXML.get_widget('statusbar1').get_context_id('The
>server replied with an unexpected error code (other than a refusal of a
>recipient).')
> self.mngCltXML.get_widget('statusbar1').push(cid_data,u'
>服务器返回错误')
> time.sleep(5)
> self.mngCltXML.get_widget('statusbar1').pop(cid_data)
>
> server.quit()
>
>
>赵威 写道:
>> Romit,您好!
>>
>> 又是遇到反垃圾邮件了...
>> 异常可以捕获到的,应该是你捕获的地方不对
>>
>> ======= 2007-12-09 12:28:52 您在来信中写道:=======
>>
>>
>>> 我为某企业写了一个向该企业员工群发电子邮件的程序,使用的是smtplib。在通
>>> 过smtp协议迭代群发邮件的时候,特别是连续发送超过32份的时候,smtp服务器拒
>>> 绝我发送请求的时候,smtplib通常会抛出一个异常:
>>> smtplib.SMTPException
>>> 紧跟着是另外一个异常:
>>> smtplib.SMTPServerDisconnected
>>> 这个异常没办法捕获到,虽然我的程序里有这个异常处理子句。
>>> 我该怎么处理这个异常?
>>>
>>> _______________________________________________
>>> python-chinese
>>> Post: send python-chinese在lists.python.cn
>>> Subscribe: send subscribe to python-chinese-request在lists.python.cn
>>> Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn
>>> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>>>
>>
>> = = = = = = = = = = = = = = = = = = = =
>>
>>
>> 致
>> 礼!
>>
>>
>> 赵威
>> zhaowei在pythonid.com
>> 2007-12-12
>>
>> _______________________________________________
>> python-chinese
>> Post: send python-chinese在lists.python.cn
>> Subscribe: send subscribe to python-chinese-request在lists.python.cn
>> Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn
>> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>_______________________________________________
>python-chinese
>Post: send python-chinese在lists.python.cn
>Subscribe: send subscribe to python-chinese-request在lists.python.cn
>Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn
>Detail Info: http://python.cn/mailman/listinfo/python-chinese
= = = = = = = = = = = = = = = = = = = =
致
礼!
赵威
zhaowei在pythonid.com
2007-12-13
2007年12月13日 星期四 16:38
我是严格按照smtplib手册上列出的异常情况进行的捕获,而且还把未提到的
socket异常也包括进去了,这个捕获不到的异常是: smtpserverdisconnected是
在smtp服务器拒绝链接后这时候程序捕获到了smtpexcept异常,然后接着是
smptserverdisconnected异常(虽然我的程序里有这个异常处理语句但是就是不调
用,很恼火啊!),我现在弄不清楚这是异常为什么程序没有处理。
赵威 写道:
> Romit,您好!
>
> 你这里的异常捕获用的
>
> try:
> except xxx:
> except xxx
>
> 这样肯定有漏掉的,要么你最后再加一个 except,要么用这样的
>
> try:
> except Exception, e:
>
>
> ======= 2007-12-12 09:52:26 您在来信中写道:=======
>
>
>> 确实是反垃圾邮件的问题,该企业会在月末向员工发送业绩、工资等信息,所以发
>> 送邮件量会比较大,我想在邮件服务器禁止发送后,程序自动等待10分钟后重试,
>> 但是每次SMTP服务器拒绝以后,随后会自动断开连接,你帮忙看一下程序存在什么
>> 问题。
>> for a in mbl:
>>
>> subject=self.mngCltXML.get_widget('entry8').get_text().encode('gb2312')
>>
>> text=self.mngCltXML.get_widget('textview1').get_buffer().get_text(self.mngCltXML.get_widget('textview1').get_buffer().get_start_iter(),self.mngCltXML.get_widget('textview1').get_buffer().get_end_iter()).encode('gb2312')
>> msg=MIMEText(text,_subtype='plain',_charset='GB2312')
>>
>> msg['Subject']=subject
>> msg['From']=conf['user']
>> msg['To']=str(a)+'@sx.133165.com'
>>
>> try:
>> server=smtplib.SMTP(conf['host'],conf['port'])
>> server.set_debuglevel(0)
>> except smtplib.SMTPException:
>>
>> cid_except=self.mngCltXML.get_widget('statusbar1').get_context_id('Base
>> exception class for all exceptions raised by this module.')
>>
>> self.mngCltXML.get_widget('statusbar1').push(cid_except,u'请更换信箱,服
>> 务器拒绝')
>> time.sleep(50)
>> self.mngCltXML.get_widget('statusbar1').pop(cid_except)
>> except smtplib.SMTPServerDisconnected:
>>
>> cid_sdiscn=self.mngCltXML.get_widget('statusbar1').get_context_id('Server
>> disconnectiod')
>>
>> self.mngCltXML.get_widget('statusbar1').pusb(cid_sdiscn,u'服务器连接中断')
>> time.sleep(5)
>> self.mngCltXML.get_widget('statusbar1').pop(cid_sdiscn)
>> except smtplib.SMTPResponseException:
>>
>> cid_rsp=self.mngCltXML.get_widget('statusbar1').get_context_id('Base
>> class for all exceptions that include an SMTP error code. These
>> exceptions are generated in some instances when the SMTP server returns
>> an error code. The error code is stored in the smtp_code attribute of
>> the error, and the smtp_error attribute is set to the error message.')
>> self.mngCltXML.get_widget('statusbar1').push(cid_rsp,u'
>> 服务器响应错误')
>> time.sleep(5)
>> self.mngCltXML.get_widget('statusbar1').pop(cid_rsp)
>> except smtplib.SMTPSenderRefused:
>>
>> cid_srfus=self.mngCltXML.get_widget('statusbar1').get_context_id('Sender
>> address refused. In addition to the attributes set by on all
>> SMTPResponseException exceptions, this sets `sender\' to the string that
>> the SMTP server refused.')
>>
>> self.mngCltXML.get_widget('statusbar1').push(cid_srfus,u'发件地址被拒绝')
>> time.sleep(600)
>> self.mngCltXML.get_widget('statusbar1').pop(cid_srfus)
>> except smtplib.SMTPRecipientsRefused:
>> #如果收件人不存在,直接跳过
>> continue
>> except smtplib.SMTPDataError:
>>
>> cid_data=self.mngCltXML.get_widget('statusbar1').get_context_id('The
>> server replied with an unexpected error code (other than a refusal of a
>> recipient).')
>> self.mngCltXML.get_widget('statusbar1').push(cid_data,u'
>> 服务器返回错误')
>> time.sleep(5)
>> self.mngCltXML.get_widget('statusbar1').pop(cid_data)
>> except smtplib.SMTPConnectError:
>>
>> cid_conn=self.mngCltXML.get_widget('statusbar1').get_context_id('Error
>> occurred during establishment of a connection with the server.')
>> self.mngCltXML.get_widget('statusbar1').push(cid_conn,u'
>> 与服务器连接错误,请更换信箱')
>> time.sleep(50)
>> self.mngCltXML.get_widget('statusbar1').pop(cid_conn)
>> except smtplib.SMTPHeloError:
>>
>> cid_helo=self.mngCltXML.get_widget('statusbar1').get_context_id('The
>> server didn\'t reply properly to the "HELO" greeting.')
>> self.mngCltXML.get_widget('statusbar1').push(cid_helo,u'
>> 服务器未正确相应')
>> time.sleep(5)
>> self.mngCltXML.get_widget('statusbar1').pop(cid_helo)
>>
>>
>> try:
>> server.login(conf['user'],conf['passwd'])
>> except smtplib.SMTPAuthenticationError:
>>
>> cid_auth=self.mngCltXML.get_widget('statusbar1').get_context_id('The
>> server didn\'t accept the username/password combination.')
>> self.mngCltXML.get_widget('statusbar1').push(cid_auth,u'
>> 用户名或者密码错误,请在SMTP 设置输入正确的用户和密码')
>> time.sleep(5)
>> self.mngCltXML.get_widget('statusbar1').pop(cid_auth)
>> except smtplib.SMTPHeloError:
>>
>> cid_helo=self.mngCltXML.get_widget('statusbar1').get_context_id('The
>> server didn\'t reply properly to the "HELO" greeting.')
>> self.mngCltXML.get_widget('statusbar1').push(cid_helo,u'
>> 服务器未正确相应')
>> time.sleep(5)
>> self.mngCltXML.get_widget('statusbar1').pop(cid_helo)
>> except smtplib.SMTPError:
>>
>> cid_err=self.mngCltXML.get_widget('statusbar1').get_context_id('No
>> suitable authentication method was found')
>> mngCltXML.get_widget('statusbar1').push(cid_err,u'验证方
>> 法不匹配')
>> break
>> self.mngCltXML.get_widget('statusbar1').pop(cid_err)
>>
>>
>> try:
>> server.sendmail(conf['user'],
>> str(a[0])+'@sx.133165.com',msg.as_string())
>> except smtplib.SMTPRecipientsRefused:
>> #如果收件人不存在,直接跳过
>> continue
>> except smtplib.SMTPHeloError:
>>
>> cid_helo=self.mngCltXML.get_widget('statusbar1').get_context_id('The
>> server didn\'t reply properly to the "HELO" greeting.')
>> self.mngCltXML.get_widget('statusbar1').push(cid_helo,u'
>> 服务器未正确相应')
>> time.sleep(5)
>> self.mngCltXML.get_widget('statusbar1').pop(cid_helo)
>> except smtplib.SMTPSenderRefused:
>> # 发件地址被拒绝通常是由于发送大量电子邮件爱你导致,所以
>> 休眠一段时间后重复发送
>> server.close()
>> time.sleep(600)
>> server=smtplib.SMTP(conf['host'],conf['port'])
>> server.server.login(conf['user'],conf['passwd'])
>>
>> except smtplib.SMTPDataError:
>>
>> cid_data=self.mngCltXML.get_widget('statusbar1').get_context_id('The
>> server replied with an unexpected error code (other than a refusal of a
>> recipient).')
>> self.mngCltXML.get_widget('statusbar1').push(cid_data,u'
>> 服务器返回错误')
>> time.sleep(5)
>> self.mngCltXML.get_widget('statusbar1').pop(cid_data)
>>
>> server.quit()
>>
>>
>> 赵威 写道:
>>
>>> Romit,您好!
>>>
>>> 又是遇到反垃圾邮件了...
>>> 异常可以捕获到的,应该是你捕获的地方不对
>>>
>>> ======= 2007-12-09 12:28:52 您在来信中写道:=======
>>>
>>>
>>>
>>>> 我为某企业写了一个向该企业员工群发电子邮件的程序,使用的是smtplib。在通
>>>> 过smtp协议迭代群发邮件的时候,特别是连续发送超过32份的时候,smtp服务器拒
>>>> 绝我发送请求的时候,smtplib通常会抛出一个异常:
>>>> smtplib.SMTPException
>>>> 紧跟着是另外一个异常:
>>>> smtplib.SMTPServerDisconnected
>>>> 这个异常没办法捕获到,虽然我的程序里有这个异常处理子句。
>>>> 我该怎么处理这个异常?
>>>>
>>>> _______________________________________________
>>>> python-chinese
>>>> Post: send python-chinese在lists.python.cn
>>>> Subscribe: send subscribe to python-chinese-request在lists.python.cn
>>>> Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn
>>>> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>>>>
>>>>
>>> = = = = = = = = = = = = = = = = = = = =
>>>
>>>
>>> 致
>>> 礼!
>>>
>>>
>>> 赵威
>>> zhaowei在pythonid.com
>>> 2007-12-12
>>>
>>> _______________________________________________
>>> python-chinese
>>> Post: send python-chinese在lists.python.cn
>>> Subscribe: send subscribe to python-chinese-request在lists.python.cn
>>> Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn
>>> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>>>
>> _______________________________________________
>> python-chinese
>> Post: send python-chinese在lists.python.cn
>> Subscribe: send subscribe to python-chinese-request在lists.python.cn
>> Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn
>> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>>
>
> = = = = = = = = = = = = = = = = = = = =
>
>
> 致
> 礼!
>
>
> 赵威
> zhaowei在pythonid.com
> 2007-12-13
>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
2007年12月14日 星期五 09:24
我不知道这个系统到时候部署到什么环境,如果是*NIX环境的话,直接让sendmail去处理好了。 sendmail可是标配,不用和邮件服务器较劲。 如果是别的平台,只能是smtp的话,因为这个问题看起来应该是服务器端的反垃圾邮件设置导致, 一个连接就发送32封邮件,不是spam我都不信 :D。所以在邮件服务器端做设置就行。 On Dec 13, 2007 4:38 PM, Romit <m_list at 126.com> wrote: > 我是严格按照smtplib手册上列出的异常情况进行的捕获,而且还把未提到的 > socket异常也包括进去了,这个捕获不到的异常是: smtpserverdisconnected是 > 在smtp服务器拒绝链接后这时候程序捕获到了smtpexcept异常,然后接着是 > smptserverdisconnected异常(虽然我的程序里有这个异常处理语句但是就是不调 > 用,很恼火啊!),我现在弄不清楚这是异常为什么程序没有处理。 > 赵威 写道: > > > Romit,您好! > > > > 你这里的异常捕获用的 > > > > try: > > except xxx: > > except xxx > > > > 这样肯定有漏掉的,要么你最后再加一个 except,要么用这样的 > > > > try: > > except Exception, e: > > > > > > ======= 2007-12-12 09:52:26 您在来信中写道:======= > > > > > >> 确实是反垃圾邮件的问题,该企业会在月末向员工发送业绩、工资等信息,所以发 > >> 送邮件量会比较大,我想在邮件服务器禁止发送后,程序自动等待10分钟后重试, > >> 但是每次SMTP服务器拒绝以后,随后会自动断开连接,你帮忙看一下程序存在什么 > >> 问题。 > >> for a in mbl: > >> > >> subject=self.mngCltXML.get_widget('entry8').get_text().encode('gb2312') > >> > >> text=self.mngCltXML.get_widget('textview1').get_buffer().get_text(self.mngCltXML.get_widget('textview1').get_buffer().get_start_iter(),self.mngCltXML.get_widget('textview1').get_buffer().get_end_iter()).encode('gb2312') > >> msg=MIMEText(text,_subtype='plain',_charset='GB2312') > >> > >> msg['Subject']=subject > >> msg['From']=conf['user'] > >> msg['To']=str(a)+'@sx.133165.com' > >> > >> try: > >> server=smtplib.SMTP(conf['host'],conf['port']) > >> server.set_debuglevel(0) > >> except smtplib.SMTPException: > >> > >> cid_except=self.mngCltXML.get_widget('statusbar1').get_context_id('Base > >> exception class for all exceptions raised by this module.') > >> > >> self.mngCltXML.get_widget('statusbar1').push(cid_except,u'请更换信箱,服 > >> 务器拒绝') > >> time.sleep(50) > >> self.mngCltXML.get_widget('statusbar1').pop(cid_except) > >> except smtplib.SMTPServerDisconnected: > >> > >> cid_sdiscn=self.mngCltXML.get_widget('statusbar1').get_context_id('Server > >> disconnectiod') > >> > >> self.mngCltXML.get_widget('statusbar1').pusb(cid_sdiscn,u'服务器连接中断') > >> time.sleep(5) > >> self.mngCltXML.get_widget('statusbar1').pop(cid_sdiscn) > >> except smtplib.SMTPResponseException: > >> > >> cid_rsp=self.mngCltXML.get_widget('statusbar1').get_context_id('Base > >> class for all exceptions that include an SMTP error code. These > >> exceptions are generated in some instances when the SMTP server returns > >> an error code. The error code is stored in the smtp_code attribute of > >> the error, and the smtp_error attribute is set to the error message.') > >> self.mngCltXML.get_widget('statusbar1').push(cid_rsp,u' > >> 服务器响应错误') > >> time.sleep(5) > >> self.mngCltXML.get_widget('statusbar1').pop(cid_rsp) > >> except smtplib.SMTPSenderRefused: > >> > >> cid_srfus=self.mngCltXML.get_widget('statusbar1').get_context_id('Sender > >> address refused. In addition to the attributes set by on all > >> SMTPResponseException exceptions, this sets `sender\' to the string that > >> the SMTP server refused.') > >> > >> self.mngCltXML.get_widget('statusbar1').push(cid_srfus,u'发件地址被拒绝') > >> time.sleep(600) > >> self.mngCltXML.get_widget('statusbar1').pop(cid_srfus) > >> except smtplib.SMTPRecipientsRefused: > >> #如果收件人不存在,直接跳过 > >> continue > >> except smtplib.SMTPDataError: > >> > >> cid_data=self.mngCltXML.get_widget('statusbar1').get_context_id('The > >> server replied with an unexpected error code (other than a refusal of a > >> recipient).') > >> self.mngCltXML.get_widget('statusbar1').push(cid_data,u' > >> 服务器返回错误') > >> time.sleep(5) > >> self.mngCltXML.get_widget('statusbar1').pop(cid_data) > >> except smtplib.SMTPConnectError: > >> > >> cid_conn=self.mngCltXML.get_widget('statusbar1').get_context_id('Error > >> occurred during establishment of a connection with the server.') > >> self.mngCltXML.get_widget('statusbar1').push(cid_conn,u' > >> 与服务器连接错误,请更换信箱') > >> time.sleep(50) > >> self.mngCltXML.get_widget('statusbar1').pop(cid_conn) > >> except smtplib.SMTPHeloError: > >> > >> cid_helo=self.mngCltXML.get_widget('statusbar1').get_context_id('The > >> server didn\'t reply properly to the "HELO" greeting.') > >> self.mngCltXML.get_widget('statusbar1').push(cid_helo,u' > >> 服务器未正确相应') > >> time.sleep(5) > >> self.mngCltXML.get_widget('statusbar1').pop(cid_helo) > >> > >> > >> try: > >> server.login(conf['user'],conf['passwd']) > >> except smtplib.SMTPAuthenticationError: > >> > >> cid_auth=self.mngCltXML.get_widget('statusbar1').get_context_id('The > >> server didn\'t accept the username/password combination.') > >> self.mngCltXML.get_widget('statusbar1').push(cid_auth,u' > >> 用户名或者密码错误,请在SMTP 设置输入正确的用户和密码') > >> time.sleep(5) > >> self.mngCltXML.get_widget('statusbar1').pop(cid_auth) > >> except smtplib.SMTPHeloError: > >> > >> cid_helo=self.mngCltXML.get_widget('statusbar1').get_context_id('The > >> server didn\'t reply properly to the "HELO" greeting.') > >> self.mngCltXML.get_widget('statusbar1').push(cid_helo,u' > >> 服务器未正确相应') > >> time.sleep(5) > >> self.mngCltXML.get_widget('statusbar1').pop(cid_helo) > >> except smtplib.SMTPError: > >> > >> cid_err=self.mngCltXML.get_widget('statusbar1').get_context_id('No > >> suitable authentication method was found') > >> mngCltXML.get_widget('statusbar1').push(cid_err,u'验证方 > >> 法不匹配') > >> break > >> self.mngCltXML.get_widget('statusbar1').pop(cid_err) > >> > >> > >> try: > >> server.sendmail(conf['user'], > >> str(a[0])+'@sx.133165.com',msg.as_string()) > >> except smtplib.SMTPRecipientsRefused: > >> #如果收件人不存在,直接跳过 > >> continue > >> except smtplib.SMTPHeloError: > >> > >> cid_helo=self.mngCltXML.get_widget('statusbar1').get_context_id('The > >> server didn\'t reply properly to the "HELO" greeting.') > >> self.mngCltXML.get_widget('statusbar1').push(cid_helo,u' > >> 服务器未正确相应') > >> time.sleep(5) > >> self.mngCltXML.get_widget('statusbar1').pop(cid_helo) > >> except smtplib.SMTPSenderRefused: > >> # 发件地址被拒绝通常是由于发送大量电子邮件爱你导致,所以 > >> 休眠一段时间后重复发送 > >> server.close() > >> time.sleep(600) > >> server=smtplib.SMTP(conf['host'],conf['port']) > >> server.server.login(conf['user'],conf['passwd']) > >> > >> except smtplib.SMTPDataError: > >> > >> cid_data=self.mngCltXML.get_widget('statusbar1').get_context_id('The > >> server replied with an unexpected error code (other than a refusal of a > >> recipient).') > >> self.mngCltXML.get_widget('statusbar1').push(cid_data,u' > >> 服务器返回错误') > >> time.sleep(5) > >> self.mngCltXML.get_widget('statusbar1').pop(cid_data) > >> > >> server.quit() > >> > >> > >> 赵威 写道: > >> > >>> Romit,您好! > >>> > >>> 又是遇到反垃圾邮件了... > >>> 异常可以捕获到的,应该是你捕获的地方不对 > >>> > >>> ======= 2007-12-09 12:28:52 您在来信中写道:======= > >>> > >>> > >>> > >>>> 我为某企业写了一个向该企业员工群发电子邮件的程序,使用的是smtplib。在通 > >>>> 过smtp协议迭代群发邮件的时候,特别是连续发送超过32份的时候,smtp服务器拒 > >>>> 绝我发送请求的时候,smtplib通常会抛出一个异常: > >>>> smtplib.SMTPException > >>>> 紧跟着是另外一个异常: > >>>> smtplib.SMTPServerDisconnected > >>>> 这个异常没办法捕获到,虽然我的程序里有这个异常处理子句。 > >>>> 我该怎么处理这个异常? > >>>> > >>>> _______________________________________________ > >>>> python-chinese > >>>> Post: send python-chinese at lists.python.cn > >>>> Subscribe: send subscribe to python-chinese-request at lists.python.cn > >>>> Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > >>>> Detail Info: http://python.cn/mailman/listinfo/python-chinese > >>>> > >>>> > >>> = = = = = = = = = = = = = = = = = = = = > >>> > >>> > >>> 致 > >>> 礼! > >>> > >>> > >>> 赵威 > >>> zhaowei at pythonid.com > >>> 2007-12-12 > >>> > >>> _______________________________________________ > >>> python-chinese > >>> Post: send python-chinese at lists.python.cn > >>> Subscribe: send subscribe to python-chinese-request at lists.python.cn > >>> Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > >>> Detail Info: http://python.cn/mailman/listinfo/python-chinese > >>> > >> _______________________________________________ > >> python-chinese > >> Post: send python-chinese at lists.python.cn > >> Subscribe: send subscribe to python-chinese-request at lists.python.cn > >> Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > >> Detail Info: http://python.cn/mailman/listinfo/python-chinese > >> > > > > = = = = = = = = = = = = = = = = = = = = > > > > > > 致 > > 礼! > > > > > > 赵威 > > zhaowei at pythonid.com > > 2007-12-13 > > > > _______________________________________________ > > python-chinese > > Post: send python-chinese at lists.python.cn > > Subscribe: send subscribe to python-chinese-request at lists.python.cn > > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese -- 关注LAMP平台、安全、及web开发的个人blog: http://hackgou.itbbq.com PGP KeyID: hackgou#Gmail.com PGP KeyServ: subkeys.pgp.net
2007年12月14日 星期五 09:38
就是在windows下环境,到月底集团将各个部门员工的信息,以电子邮件的形式直
接发送到用户注册的信箱里,所以量会很大,其实一个smtp session只能发两份电
子邮件,所以我的程序其实是不停地迭代发送。smtp出于反垃圾邮件考虑肯定要拒
绝链接。
那么:
smtp client ------->smtp server
|
|
返回错误信息<---------+
主动中断链接<----X----+
返回错误信息的异常我能捕获到,但是随后服务器的主动中断链接我的程序里有这
个异常处理但是没办法捕获到。
憨狗 写道:
> 我不知道这个系统到时候部署到什么环境,如果是*NIX环境的话,直接让sendmail去处理好了。
> sendmail可是标配,不用和邮件服务器较劲。
> 如果是别的平台,只能是smtp的话,因为这个问题看起来应该是服务器端的反垃圾邮件设置导致,
> 一个连接就发送32封邮件,不是spam我都不信 :D。所以在邮件服务器端做设置就行。
>
>
>
>
> On Dec 13, 2007 4:38 PM, Romit <m_list在126.com> wrote:
>
>> 我是严格按照smtplib手册上列出的异常情况进行的捕获,而且还把未提到的
>> socket异常也包括进去了,这个捕获不到的异常是: smtpserverdisconnected是
>> 在smtp服务器拒绝链接后这时候程序捕获到了smtpexcept异常,然后接着是
>> smptserverdisconnected异常(虽然我的程序里有这个异常处理语句但是就是不调
>> 用,很恼火啊!),我现在弄不清楚这是异常为什么程序没有处理。
>> 赵威 写道:
>>
>>
>>> Romit,您好!
>>>
>>> 你这里的异常捕获用的
>>>
>>> try:
>>> except xxx:
>>> except xxx
>>>
>>> 这样肯定有漏掉的,要么你最后再加一个 except,要么用这样的
>>>
>>> try:
>>> except Exception, e:
>>>
>>>
>>> ======= 2007-12-12 09:52:26 您在来信中写道:=======
>>>
>>>
>>>
>>>> 确实是反垃圾邮件的问题,该企业会在月末向员工发送业绩、工资等信息,所以发
>>>> 送邮件量会比较大,我想在邮件服务器禁止发送后,程序自动等待10分钟后重试,
>>>> 但是每次SMTP服务器拒绝以后,随后会自动断开连接,你帮忙看一下程序存在什么
>>>> 问题。
>>>> for a in mbl:
>>>>
>>>> subject=self.mngCltXML.get_widget('entry8').get_text().encode('gb2312')
>>>>
>>>> text=self.mngCltXML.get_widget('textview1').get_buffer().get_text(self.mngCltXML.get_widget('textview1').get_buffer().get_start_iter(),self.mngCltXML.get_widget('textview1').get_buffer().get_end_iter()).encode('gb2312')
>>>> msg=MIMEText(text,_subtype='plain',_charset='GB2312')
>>>>
>>>> msg['Subject']=subject
>>>> msg['From']=conf['user']
>>>> msg['To']=str(a)+'@sx.133165.com'
>>>>
>>>> try:
>>>> server=smtplib.SMTP(conf['host'],conf['port'])
>>>> server.set_debuglevel(0)
>>>> except smtplib.SMTPException:
>>>>
>>>> cid_except=self.mngCltXML.get_widget('statusbar1').get_context_id('Base
>>>> exception class for all exceptions raised by this module.')
>>>>
>>>> self.mngCltXML.get_widget('statusbar1').push(cid_except,u'请更换信箱,服
>>>> 务器拒绝')
>>>> time.sleep(50)
>>>> self.mngCltXML.get_widget('statusbar1').pop(cid_except)
>>>> except smtplib.SMTPServerDisconnected:
>>>>
>>>> cid_sdiscn=self.mngCltXML.get_widget('statusbar1').get_context_id('Server
>>>> disconnectiod')
>>>>
>>>> self.mngCltXML.get_widget('statusbar1').pusb(cid_sdiscn,u'服务器连接中断')
>>>> time.sleep(5)
>>>> self.mngCltXML.get_widget('statusbar1').pop(cid_sdiscn)
>>>> except smtplib.SMTPResponseException:
>>>>
>>>> cid_rsp=self.mngCltXML.get_widget('statusbar1').get_context_id('Base
>>>> class for all exceptions that include an SMTP error code. These
>>>> exceptions are generated in some instances when the SMTP server returns
>>>> an error code. The error code is stored in the smtp_code attribute of
>>>> the error, and the smtp_error attribute is set to the error message.')
>>>> self.mngCltXML.get_widget('statusbar1').push(cid_rsp,u'
>>>> 服务器响应错误')
>>>> time.sleep(5)
>>>> self.mngCltXML.get_widget('statusbar1').pop(cid_rsp)
>>>> except smtplib.SMTPSenderRefused:
>>>>
>>>> cid_srfus=self.mngCltXML.get_widget('statusbar1').get_context_id('Sender
>>>> address refused. In addition to the attributes set by on all
>>>> SMTPResponseException exceptions, this sets `sender\' to the string that
>>>> the SMTP server refused.')
>>>>
>>>> self.mngCltXML.get_widget('statusbar1').push(cid_srfus,u'发件地址被拒绝')
>>>> time.sleep(600)
>>>> self.mngCltXML.get_widget('statusbar1').pop(cid_srfus)
>>>> except smtplib.SMTPRecipientsRefused:
>>>> #如果收件人不存在,直接跳过
>>>> continue
>>>> except smtplib.SMTPDataError:
>>>>
>>>> cid_data=self.mngCltXML.get_widget('statusbar1').get_context_id('The
>>>> server replied with an unexpected error code (other than a refusal of a
>>>> recipient).')
>>>> self.mngCltXML.get_widget('statusbar1').push(cid_data,u'
>>>> 服务器返回错误')
>>>> time.sleep(5)
>>>> self.mngCltXML.get_widget('statusbar1').pop(cid_data)
>>>> except smtplib.SMTPConnectError:
>>>>
>>>> cid_conn=self.mngCltXML.get_widget('statusbar1').get_context_id('Error
>>>> occurred during establishment of a connection with the server.')
>>>> self.mngCltXML.get_widget('statusbar1').push(cid_conn,u'
>>>> 与服务器连接错误,请更换信箱')
>>>> time.sleep(50)
>>>> self.mngCltXML.get_widget('statusbar1').pop(cid_conn)
>>>> except smtplib.SMTPHeloError:
>>>>
>>>> cid_helo=self.mngCltXML.get_widget('statusbar1').get_context_id('The
>>>> server didn\'t reply properly to the "HELO" greeting.')
>>>> self.mngCltXML.get_widget('statusbar1').push(cid_helo,u'
>>>> 服务器未正确相应')
>>>> time.sleep(5)
>>>> self.mngCltXML.get_widget('statusbar1').pop(cid_helo)
>>>>
>>>>
>>>> try:
>>>> server.login(conf['user'],conf['passwd'])
>>>> except smtplib.SMTPAuthenticationError:
>>>>
>>>> cid_auth=self.mngCltXML.get_widget('statusbar1').get_context_id('The
>>>> server didn\'t accept the username/password combination.')
>>>> self.mngCltXML.get_widget('statusbar1').push(cid_auth,u'
>>>> 用户名或者密码错误,请在SMTP 设置输入正确的用户和密码')
>>>> time.sleep(5)
>>>> self.mngCltXML.get_widget('statusbar1').pop(cid_auth)
>>>> except smtplib.SMTPHeloError:
>>>>
>>>> cid_helo=self.mngCltXML.get_widget('statusbar1').get_context_id('The
>>>> server didn\'t reply properly to the "HELO" greeting.')
>>>> self.mngCltXML.get_widget('statusbar1').push(cid_helo,u'
>>>> 服务器未正确相应')
>>>> time.sleep(5)
>>>> self.mngCltXML.get_widget('statusbar1').pop(cid_helo)
>>>> except smtplib.SMTPError:
>>>>
>>>> cid_err=self.mngCltXML.get_widget('statusbar1').get_context_id('No
>>>> suitable authentication method was found')
>>>> mngCltXML.get_widget('statusbar1').push(cid_err,u'验证方
>>>> 法不匹配')
>>>> break
>>>> self.mngCltXML.get_widget('statusbar1').pop(cid_err)
>>>>
>>>>
>>>> try:
>>>> server.sendmail(conf['user'],
>>>> str(a[0])+'@sx.133165.com',msg.as_string())
>>>> except smtplib.SMTPRecipientsRefused:
>>>> #如果收件人不存在,直接跳过
>>>> continue
>>>> except smtplib.SMTPHeloError:
>>>>
>>>> cid_helo=self.mngCltXML.get_widget('statusbar1').get_context_id('The
>>>> server didn\'t reply properly to the "HELO" greeting.')
>>>> self.mngCltXML.get_widget('statusbar1').push(cid_helo,u'
>>>> 服务器未正确相应')
>>>> time.sleep(5)
>>>> self.mngCltXML.get_widget('statusbar1').pop(cid_helo)
>>>> except smtplib.SMTPSenderRefused:
>>>> # 发件地址被拒绝通常是由于发送大量电子邮件爱你导致,所以
>>>> 休眠一段时间后重复发送
>>>> server.close()
>>>> time.sleep(600)
>>>> server=smtplib.SMTP(conf['host'],conf['port'])
>>>> server.server.login(conf['user'],conf['passwd'])
>>>>
>>>> except smtplib.SMTPDataError:
>>>>
>>>> cid_data=self.mngCltXML.get_widget('statusbar1').get_context_id('The
>>>> server replied with an unexpected error code (other than a refusal of a
>>>> recipient).')
>>>> self.mngCltXML.get_widget('statusbar1').push(cid_data,u'
>>>> 服务器返回错误')
>>>> time.sleep(5)
>>>> self.mngCltXML.get_widget('statusbar1').pop(cid_data)
>>>>
>>>> server.quit()
>>>>
>>>>
>>>> 赵威 写道:
>>>>
>>>>
>>>>> Romit,您好!
>>>>>
>>>>> 又是遇到反垃圾邮件了...
>>>>> 异常可以捕获到的,应该是你捕获的地方不对
>>>>>
>>>>> ======= 2007-12-09 12:28:52 您在来信中写道:=======
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>> 我为某企业写了一个向该企业员工群发电子邮件的程序,使用的是smtplib。在通
>>>>>> 过smtp协议迭代群发邮件的时候,特别是连续发送超过32份的时候,smtp服务器拒
>>>>>> 绝我发送请求的时候,smtplib通常会抛出一个异常:
>>>>>> smtplib.SMTPException
>>>>>> 紧跟着是另外一个异常:
>>>>>> smtplib.SMTPServerDisconnected
>>>>>> 这个异常没办法捕获到,虽然我的程序里有这个异常处理子句。
>>>>>> 我该怎么处理这个异常?
>>>>>>
>>>>>> _______________________________________________
>>>>>> python-chinese
>>>>>> Post: send python-chinese在lists.python.cn
>>>>>> Subscribe: send subscribe to python-chinese-request在lists.python.cn
>>>>>> Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn
>>>>>> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>>>>>>
>>>>>>
>>>>>>
>>>>> = = = = = = = = = = = = = = = = = = = =
>>>>>
>>>>>
>>>>> 致
>>>>> 礼!
>>>>>
>>>>>
>>>>> 赵威
>>>>> zhaowei在pythonid.com
>>>>> 2007-12-12
>>>>>
>>>>> _______________________________________________
>>>>> python-chinese
>>>>> Post: send python-chinese在lists.python.cn
>>>>> Subscribe: send subscribe to python-chinese-request在lists.python.cn
>>>>> Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn
>>>>> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>>>>>
>>>>>
>>>> _______________________________________________
>>>> python-chinese
>>>> Post: send python-chinese在lists.python.cn
>>>> Subscribe: send subscribe to python-chinese-request在lists.python.cn
>>>> Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn
>>>> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>>>>
>>>>
>>> = = = = = = = = = = = = = = = = = = = =
>>>
>>>
>>> 致
>>> 礼!
>>>
>>>
>>> 赵威
>>> zhaowei在pythonid.com
>>> 2007-12-13
>>>
>>> _______________________________________________
>>> python-chinese
>>> Post: send python-chinese在lists.python.cn
>>> Subscribe: send subscribe to python-chinese-request在lists.python.cn
>>> Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn
>>> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>>>
>> _______________________________________________
>> python-chinese
>> Post: send python-chinese在lists.python.cn
>> Subscribe: send subscribe to python-chinese-request在lists.python.cn
>> Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn
>> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>>
>
>
>
>
Zeuux © 2025
京ICP备05028076号