SmtpClient从服务器上发送结果器上、结果、SmtpClient

2023-09-04 09:09:22 作者:情歌王

该SmtpClient发送方法返回void。有没有什么办法让服务器响应?难道我只是假设它是成功的,除非它抛出一个异常?

The SmtpClient send method returns void. Is there any way to get the server response? Do I just assume it was successful unless it throws an exception?

我指的是... http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx

推荐答案

要回答你的第二点,是的,你可以做的是假设它是成功的 - 这意味着它得到了消息给服务器,服务器接受了它,除非你得到一个例外。

To answer your second point, yes, all you can do is assume it's successful - meaning it got the message to the server and the server accepted it, unless you get an exception.

您可能已经知道这剩下的,但以防万一...

You probably already know the rest of this, but just in case...

从那里,电子邮件可以迷路和不传递任何数目的方式。您的服务器可能会接受它,并决定不发送,或者接受它,并坠毁前失去动力。这可能会阻止前进的道路上,等垃圾邮件过滤器。

From there, the email could get lost and not delivered any number of ways. Your server may accept it and decide not to send it, or accept it and lose power before crashing. It may get blocked by a spam filter along the way, etc.

可以想到一个电子邮件作为是类似于一个普通邮件,它穿过发送者和接收者之间的若干手。从code,你只能确认它得到你使用发送SMTP服务器,它类似于递给出纳员在邮局。你不知道(或需要知道)如何将消息从那里路由。它可能是由空气,地面,或信鸽。你的方程 - 你不需要知道它是如何被发送,只要你相信,他们知道如何发送它。 (同样可以说是电子邮件。)

You can think of an email as being similar to a regular piece of mail in that it passes through several hands between the sender and the recipient. From your code, you can only confirm that it got to the SMTP server you're using to send, which is similar to handing it to a teller at the post office. You don't know (or need to know) how the message is routed from there. it could be by air, ground, or carrier pigeon. You're out of the equation - you don't need to know how it gets sent, just that you trust that they know how to send it. (The same can be said for an email.)

如果您需要确认收件人打开一看,有您的服务器上的HTML邮件中嵌入图像,并跟踪你的日志时,该图像被访问等方式(谷歌邮件跟踪和邮件打开跟踪)

If you need to confirm that the recipient opened it, there are ways of embedding an image in an HTML message on your server and tracking in your logs when that image is accessed, etc. (Google email tracking and email open tracking)

在另一方面...

如果服务器拒绝它,那么你得到的说话的方式的服务器响应 - 应该有一个错误code和错误,你可以用它来解决,为什么它没有说明它或使用错误处理,尝试其他途径,等等。

If the server rejects it, then you do get a server response in a manner of speaking - there should be an error code and a description in the error, which you can use to troubleshoot why it didn't make it, or use error handling to try another route, etc.