如何正确设置IIS5的SMTP服务以从开发环境发送电子邮件?

时间:2021-01-21 07:36:15

I am trying to send email from an ASP.NET web application using the SmtpClient class. So far I have granted relay access to 127.0.0.1. I am trying to send test emails to my gmail account. The EML files get stuck in the mailroot's queue folder. My WinXP firewall is disabled. I dont get any exceptions in the code but the emails are never delivered to the destination address. I also tried other email accounts.

我正在尝试从ASP发送电子邮件。使用SmtpClient类的NET web应用程序。到目前为止,我已经授予了对127.0.0.1的中继访问权。我想把测试邮件发送到我的gmail账户。EML文件卡在mailroot的队列文件夹中。我的WinXP防火墙被禁用。我在代码中没有任何例外,但这些邮件从未被发送到目的地地址。我还尝试了其他的电子邮件账户。

        SmtpClient client = new SmtpClient();
        client.Host = "127.0.0.1";

        MailMessage message = new MailMessage();
        message.To.Add("myemail@gmail.com");
        message.From = "name@domain.com";
        message.Subject = subject;
        message.IsBodyHtml = false;
        message.Body = body;

        client.Send(message);

Here is a snippet from the IIS SMTP log.

下面是IIS SMTP日志中的一个片段。

Software: Microsoft Internet Information Services 5.1
Version: 1.0
Date: 2009-01-16 18:28:28
Fields: time c-ip cs-method cs-uri-stem sc-status 
18:28:28 127.0.0.1 EHLO - 250
18:28:28 127.0.0.1 MAIL - 250
18:28:28 127.0.0.1 RCPT - 250
18:28:28 127.0.0.1 DATA - 250
18:29:45 127.0.0.1 MAIL - 250
18:29:45 127.0.0.1 RCPT - 250
18:29:45 127.0.0.1 DATA - 250
18:30:37 127.0.0.1 QUIT - 0

5 个解决方案

#1


1  

Depending on how your network is set up, you might need to tell IIS to pass on emails to your Exchange server to be passed on to the outside world. To do this:
1. Right-click on the Default SMTP Virtual Server node in the IIS MMC Snap-in and open the Properties dialog.
2. Go to the Delivery tab and click on the Advanced button at the bottom of the tab.
3. In the Smart Host box, enter the name of your Exchange server. (Or a DNS entry for the same e.g. smtp.mydomain.com)

根据您的网络是如何设置的,您可能需要告诉IIS将电子邮件传递到您的Exchange服务器以传递到外部世界。这样做:1。右键单击IIS MMC中的默认SMTP虚拟服务器节点,并打开属性对话框。2。转到Delivery选项卡并单击选项卡底部的Advanced按钮。3所示。在智能主机框中,输入Exchange服务器的名称。(或同样的DNS条目,例如smtp.mydomain.com)

#2


1  

I've just been fighting with the same problem and I think I know why - and the solution.

我一直在与同样的问题作斗争,我想我知道原因——以及解决办法。

The problem and how to test for it
Firstly, I checked that I could connect out over port 25. Easily done by opening telnet in a command prompt and typing, for example (the little circle is the letter O on it's own, not a symbol :));

问题和如何进行测试首先,我检查了我是否可以通过25端口进行连接。通过在命令提示符中打开telnet并输入(例如,小圆圈是它自己的字母O,而不是符号:);

 o auth.smtp.1and1.co.uk 25

If that connects (rather than gives you an error) then it's not a firewall problem with port 25. If it does give you an error then first check your firewall settings until this works.

如果连接(而不是给您一个错误),那么端口25不是防火墙问题。如果它确实给您一个错误,那么首先检查您的防火墙设置,直到它工作。

Next I enabled logging in the SMTP service and ticked all the extended properties. This then gave me two URLs in the log file. In my case they were
http://www.spamhaus.org/query/bl?ip=217.44.248.144
http://www.sorbs.net/lookup.shtml?217.44.248.144

接下来,我启用了SMTP服务中的日志记录,并标记了所有扩展属性。这给了我日志文件中的两个url。在我的例子中,它们是http://www.spamhaus.org/query/bl?

Following those links it basically became clear that someone out there (I guess the receiving server) is checking and seeing that I am sending from a dynamic IP Address (I am just doing this from home over ADSL) and so blocking it as SPAM.

在这些链接之后,很明显有人(我猜是接收服务器)正在检查并看到我正在从一个动态IP地址发送(我只是在家里通过ADSL发送),因此将其作为垃圾邮件进行拦截。

The solution
You need to configure your SMTP Server to relay via your ISP's SMTP Server.
1. Go to the Properties for the SMTP Service and go to Delivery -> Advanced
2. Put the name of your ISP's SMTP server in the "Smart host" field (for example auth.smtp.1and1.co.uk)
3. Save that
4. Back on the Delivery tab, click on the Outbound Security tab
5. Click on "basic authentication" and specify the username and password you use to access your email.

您需要将SMTP服务器配置为通过ISP的SMTP服务器进行中继的解决方案。转到SMTP服务的属性,转到Delivery ->高级2。在“智能主机”字段(例如auth.smtp.1and1.co.uk)中输入ISP的SMTP服务器的名称。保存4。返回发送选项卡,单击出站安全选项卡5。单击“基本身份验证”,并指定用于访问电子邮件的用户名和密码。

Note; I have assumed above that you have to authenticate to your ISPs SMTP server and that they use the same uid/pwd for POP3/IMAP and SMTP as that is the most common. Your situation may vary - check your email settings in your email program.

请注意;我已经假设您必须对您的ISPs SMTP服务器进行身份验证,并且他们对POP3/IMAP和SMTP使用相同的uid/pwd,这是最常见的。您的情况可能会有所不同——检查您的电子邮件程序中的电子邮件设置。

#3


0  

I am still testing this Jim, one thing that I have noticed is that you are not setting your from address correctly. From accepts a MailAddress class not a string.

我还在测试这个Jim,我注意到的一件事是你没有正确地设置你的地址。从接收邮件地址类而不是字符串。

Change:

变化:

message.From = "name@domain.com";

To:

:

message.From = new MailAddress("name@domain.com");

Under Default SMTP settings:

在默认SMTP设置:

Is the "IP address:" dropdown set to 127.0.0.1 or (All Unassigned)? If possible have it set to All Unassigned. Try adding the ip address bound to your machine to be able to relay through the SMTP service. Though your sending email to your host 127.0.0.1, it may be sending it from your local network assigned ip. To make sure stuff is working you may want to select the radio button in Relay Restrictions to "All except the list below" and clear the list. This will open up the relay to test your configuration. You should restrict this once you figure out what your issue is.

“IP地址:”下拉列表设置为127.0.0.1还是(全部未分配)?如果可能的话,将它设置为所有未分配的。尝试将绑定的ip地址添加到您的机器上,以便能够通过SMTP服务进行中继。虽然您的邮件发送到您的主机127.0.0.1,它可能是从您的本地网络分配ip。为了确保你的工作是正常的,你可能想要选择“除了下面的列表之外的所有”的中继限制中的单选按钮,并清除列表。这将打开继电器来测试您的配置。一旦你弄清楚你的问题是什么,你就应该限制它。

Are there any error codes listed in your SMTP log?

SMTP日志中是否列出了错误代码?

#4


0  

If the code returns no exceptions then it's unlikely to be anything there. If you look at the raw .EML file, check through there and look for anything out of place.

如果代码不返回任何异常,那么不太可能有任何异常。如果您查看原始的. eml文件,请检查其中的内容并查找不合适的内容。

However, the most likely problem is just give IIS a kick "iisreset". Do that and you'll probably see the messages start to get sent. Configuration changes on the SMTP server don't always come into play until a restart.

然而,最可能的问题是给IIS一个“iisreset”。这样做,您可能会看到消息开始被发送。在重新启动之前,SMTP服务器上的配置更改并不总是起作用。

#5


0  

Check your event viewer, then you will see something like this

检查事件查看器,您将看到类似的内容

Message delivery to the remote domain 'yahoo.com' failed for the following reason: An SMTP protocol error occurred.

发送到远程域“yahoo.com”的消息失败的原因如下:发生了SMTP协议错误。

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

有关更多信息,请参见http://go.microsoft.com/fwlink/events.asp的帮助和支持中心。

(This is mine). I think yahoo must have some kind of protocol? Or we are setting the wrong protocol? Still figuring.. Email me pls jokenjp@yahoo.com (with a nice subject so I don't think as spam)

(这是我)。我认为雅虎一定有某种协议?还是我们设置了错误的协议?还算. .请发邮件给我jokenjp@yahoo.com(标题不错,所以我不认为是垃圾邮件)

#1


1  

Depending on how your network is set up, you might need to tell IIS to pass on emails to your Exchange server to be passed on to the outside world. To do this:
1. Right-click on the Default SMTP Virtual Server node in the IIS MMC Snap-in and open the Properties dialog.
2. Go to the Delivery tab and click on the Advanced button at the bottom of the tab.
3. In the Smart Host box, enter the name of your Exchange server. (Or a DNS entry for the same e.g. smtp.mydomain.com)

根据您的网络是如何设置的,您可能需要告诉IIS将电子邮件传递到您的Exchange服务器以传递到外部世界。这样做:1。右键单击IIS MMC中的默认SMTP虚拟服务器节点,并打开属性对话框。2。转到Delivery选项卡并单击选项卡底部的Advanced按钮。3所示。在智能主机框中,输入Exchange服务器的名称。(或同样的DNS条目,例如smtp.mydomain.com)

#2


1  

I've just been fighting with the same problem and I think I know why - and the solution.

我一直在与同样的问题作斗争,我想我知道原因——以及解决办法。

The problem and how to test for it
Firstly, I checked that I could connect out over port 25. Easily done by opening telnet in a command prompt and typing, for example (the little circle is the letter O on it's own, not a symbol :));

问题和如何进行测试首先,我检查了我是否可以通过25端口进行连接。通过在命令提示符中打开telnet并输入(例如,小圆圈是它自己的字母O,而不是符号:);

 o auth.smtp.1and1.co.uk 25

If that connects (rather than gives you an error) then it's not a firewall problem with port 25. If it does give you an error then first check your firewall settings until this works.

如果连接(而不是给您一个错误),那么端口25不是防火墙问题。如果它确实给您一个错误,那么首先检查您的防火墙设置,直到它工作。

Next I enabled logging in the SMTP service and ticked all the extended properties. This then gave me two URLs in the log file. In my case they were
http://www.spamhaus.org/query/bl?ip=217.44.248.144
http://www.sorbs.net/lookup.shtml?217.44.248.144

接下来,我启用了SMTP服务中的日志记录,并标记了所有扩展属性。这给了我日志文件中的两个url。在我的例子中,它们是http://www.spamhaus.org/query/bl?

Following those links it basically became clear that someone out there (I guess the receiving server) is checking and seeing that I am sending from a dynamic IP Address (I am just doing this from home over ADSL) and so blocking it as SPAM.

在这些链接之后,很明显有人(我猜是接收服务器)正在检查并看到我正在从一个动态IP地址发送(我只是在家里通过ADSL发送),因此将其作为垃圾邮件进行拦截。

The solution
You need to configure your SMTP Server to relay via your ISP's SMTP Server.
1. Go to the Properties for the SMTP Service and go to Delivery -> Advanced
2. Put the name of your ISP's SMTP server in the "Smart host" field (for example auth.smtp.1and1.co.uk)
3. Save that
4. Back on the Delivery tab, click on the Outbound Security tab
5. Click on "basic authentication" and specify the username and password you use to access your email.

您需要将SMTP服务器配置为通过ISP的SMTP服务器进行中继的解决方案。转到SMTP服务的属性,转到Delivery ->高级2。在“智能主机”字段(例如auth.smtp.1and1.co.uk)中输入ISP的SMTP服务器的名称。保存4。返回发送选项卡,单击出站安全选项卡5。单击“基本身份验证”,并指定用于访问电子邮件的用户名和密码。

Note; I have assumed above that you have to authenticate to your ISPs SMTP server and that they use the same uid/pwd for POP3/IMAP and SMTP as that is the most common. Your situation may vary - check your email settings in your email program.

请注意;我已经假设您必须对您的ISPs SMTP服务器进行身份验证,并且他们对POP3/IMAP和SMTP使用相同的uid/pwd,这是最常见的。您的情况可能会有所不同——检查您的电子邮件程序中的电子邮件设置。

#3


0  

I am still testing this Jim, one thing that I have noticed is that you are not setting your from address correctly. From accepts a MailAddress class not a string.

我还在测试这个Jim,我注意到的一件事是你没有正确地设置你的地址。从接收邮件地址类而不是字符串。

Change:

变化:

message.From = "name@domain.com";

To:

:

message.From = new MailAddress("name@domain.com");

Under Default SMTP settings:

在默认SMTP设置:

Is the "IP address:" dropdown set to 127.0.0.1 or (All Unassigned)? If possible have it set to All Unassigned. Try adding the ip address bound to your machine to be able to relay through the SMTP service. Though your sending email to your host 127.0.0.1, it may be sending it from your local network assigned ip. To make sure stuff is working you may want to select the radio button in Relay Restrictions to "All except the list below" and clear the list. This will open up the relay to test your configuration. You should restrict this once you figure out what your issue is.

“IP地址:”下拉列表设置为127.0.0.1还是(全部未分配)?如果可能的话,将它设置为所有未分配的。尝试将绑定的ip地址添加到您的机器上,以便能够通过SMTP服务进行中继。虽然您的邮件发送到您的主机127.0.0.1,它可能是从您的本地网络分配ip。为了确保你的工作是正常的,你可能想要选择“除了下面的列表之外的所有”的中继限制中的单选按钮,并清除列表。这将打开继电器来测试您的配置。一旦你弄清楚你的问题是什么,你就应该限制它。

Are there any error codes listed in your SMTP log?

SMTP日志中是否列出了错误代码?

#4


0  

If the code returns no exceptions then it's unlikely to be anything there. If you look at the raw .EML file, check through there and look for anything out of place.

如果代码不返回任何异常,那么不太可能有任何异常。如果您查看原始的. eml文件,请检查其中的内容并查找不合适的内容。

However, the most likely problem is just give IIS a kick "iisreset". Do that and you'll probably see the messages start to get sent. Configuration changes on the SMTP server don't always come into play until a restart.

然而,最可能的问题是给IIS一个“iisreset”。这样做,您可能会看到消息开始被发送。在重新启动之前,SMTP服务器上的配置更改并不总是起作用。

#5


0  

Check your event viewer, then you will see something like this

检查事件查看器,您将看到类似的内容

Message delivery to the remote domain 'yahoo.com' failed for the following reason: An SMTP protocol error occurred.

发送到远程域“yahoo.com”的消息失败的原因如下:发生了SMTP协议错误。

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

有关更多信息,请参见http://go.microsoft.com/fwlink/events.asp的帮助和支持中心。

(This is mine). I think yahoo must have some kind of protocol? Or we are setting the wrong protocol? Still figuring.. Email me pls jokenjp@yahoo.com (with a nice subject so I don't think as spam)

(这是我)。我认为雅虎一定有某种协议?还是我们设置了错误的协议?还算. .请发邮件给我jokenjp@yahoo.com(标题不错,所以我不认为是垃圾邮件)