Python-管理错误消息(电子邮件发送)
我试图在电子邮件运输过程中没有错误并在有错误时进行操作时打印一条消息。
我尝试了一下,但没有任何效果,错误消息停止了一切。
如何隐藏错误消息并用我自己的替换并替换该错误消息。
import win32com.client as win32
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = '[email protected]'
mail.Subject = 'TEST'
mail.Body = 'Hello'
mail.Send()
try :
print("mail sent")
except BaseException as e:
print("mail not sent")
fonction()
I'm trying to print a message when there's no error during the shipping of the email and doing an action if there's an error.
I gave it a try but nothing worked, the error message stop everything.
How hide the error message and replace it with my own and keep with an action.
import win32com.client as win32
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = '[email protected]'
mail.Subject = 'TEST'
mail.Body = 'Hello'
mail.Send()
try :
print("mail sent")
except BaseException as e:
print("mail not sent")
fonction()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要编写要在
中测试的代码,请尝试
块。对于您的消息打印问题,您可以尝试else
try-except
的块。else
如果在中没有错误
block中没有错误,则块执行。因此,请尝试以下操作:You need write the code you want to test inside
try
block. And for your message printing problem you can try theelse
block oftry-except
.else
block executes if there is no error intry
block. So try this: