Can I test SmtpClient before calling client.Send()?

前端 未结 6 737
夕颜
夕颜 2020-11-28 10:58

This is related to a question I asked the other day on how to send email.

My new, related question is this... what if the user of my application is behind a firew

6条回答
  •  有刺的猬
    2020-11-28 11:37

    Catch the SmtpException exception, it will tell you if it failed because you couldn't connect to the server.

    If you want to check if you can open a connection to the server before any attempt, Use TcpClient and catch SocketExceptions. Though I don't see any benefit to doing this vs just catching problems from Smtp.Send.

提交回复
热议问题