如何在Vista上设置smtp以便我可以使用System.Net.Mail?

时间:2021-12-14 10:06:35

From what I understand there is no SMTP server in IIS on Vista. I am working on a project which will require me to send email. I'd like to start with some simple prototypes on my development box which is running Vista Ultimate. I'm not connected to a corporate network where I can just use an exchange server someplace.

据我所知,Vista上的IIS中没有SMTP服务器。我正在开展一个项目,要求我发送电子邮件。我想从运行Vista Ultimate的开发盒开始使用一些简单的原型。我没有连接到公司网络,我可以在某个地方使用交换服务器。

I realize that there are several smtp servers that I can install, but I'm not sure what to do once I install one. I know how to write the code to send the email, but I don't know what kind of configuration needs to be done to use the smtp server.

我意识到我可以安装几个smtp服务器,但是一旦我安装了一个服务器,我不知道该怎么办。我知道如何编写代码来发送电子邮件,但我不知道使用smtp服务器需要做什么样的配置。

What I'd like is a clear description of what to do once I get an smtp server installed on my Vista box.

我想要的是一个清晰的描述,一旦我在我的Vista盒子上安装了smtp服务器该怎么做。

Thanks!

UPDATE: I downloaded this smtp server: http://softstack.com/freesmtp.html

更新:我下载了这个smtp服务器:http://softstack.com/freesmtp.html

Here's what my code looks like:

这是我的代码的样子:

class Program
{
    static void Main(string[] args)
    {
        MailMessage message = new MailMessage();    
        message.From = new MailAddress("tad@myconsoleapp.com");    
        message.To.Add(new MailAddress("terry.donaghe@gmail.com"));               
        //message.To.Add(new MailAddress("recipient3@foo.bar.com"));    
        //message.CC.Add(new MailAddress("carboncopy@foo.bar.com"));    
        message.Subject = "This is my subject";    
        message.Body = "This is the content";    
        SmtpClient client = new SmtpClient("localhost");    
        client.Send(message);    
        Console.ReadLine();     
    }
}

When I have this smtp server running and I execute my console app, it hands on the client.send line. The smtp server looks like this:

当我运行这个smtp服务器并执行我的控制台应用程序时,它会移动client.send行。 smtp服务器看起来像这样:

http://screencast.com/t/2B7jv0bE14

After a while the client.send times out.

过了一会儿,client.send超时了。

Any ideas what's going wrong now?

任何想法现在出了什么问题?

Thanks!

4 个解决方案

#1


As you know SMTP no longer ships with Vista (Which is one of my biggest complaints about Vista). As you already know there are many options out there, and if you found a good free one post a link to it. How you configure it will probally depend on the server you install.

如你所知,SMTP不再附带Vista(这是我对Vista的最大抱怨之一)。你已经知道有很多选择,如果你找到一个好的免费发布链接到它。您如何配置它将取决于您安装的服务器。

I played around with some trial smtp servers, and all the ones I used started listening on the standard SMTP ports on the loopback IP Address. I believe this is the default MailSettings, and shouldn't require any changes.

我玩了一些试用smtp服务器,我使用的所有服务器都开始监听环回IP地址上的标准SMTP端口。我相信这是默认的MailSettings,不应该要求任何更改。

I no longer have any SMTP server and am using the Pickup Directory mode. This causes the mail library to output a file which I can then inspect.

我不再拥有任何SMTP服务器并且正在使用分拣目录模式。这会导致邮件库输出一个我可以检查的文件。

To configure this use the following in your config file:

要配置它,请在配置文件中使用以下内容:

<system.net>
    <mailSettings>
        <smtp deliveryMethod="SpecifiedPickupDirectory">
            <specifiedPickupDirectory
              pickupDirectoryLocation="c:\maildrop"/>
        </smtp>
    </mailSettings>
</system.net>

If you want to configure it to connect to port 25 on your local host you would this for the SMTP section:

如果要将其配置为连接到本地主机上的端口25,则可以使用SMTP部分:

<smtp deliveryMethod="Network">
   <network defaultCredentials="true" host="localhost" port="25"/>
</smtp>

Edit

Terry asked a good question about using the drop location. I only use this for testing, as our production server has an SMTP server which I connect to, and send the email through; however, some SMTP servers can be configured to watch a directory and will pick up and mail anything in there.

特里问了一个关于使用掉落位置的好问题。我只使用它进行测试,因为我们的生产服务器有一个我连接的SMTP服务器,并通过以下方式发送电子邮件;但是,某些SMTP服务器可以配置为监视目录,并将拾取并邮寄其中的任何内容。

I don't think this feature was meant to be used only for testing but it works nicely. The files that get generated can be opened in various mail clients so you can see how they would render them. I belive they .eml files but I can't remember.

我认为这个功能不仅仅用于测试,但效果很好。生成的文件可以在各种邮件客户端中打开,这样您就可以看到它们如何呈现它们。我相信他们的.eml文件,但我不记得了。

#2


You can find a very basic SMTP server coded in C# .NET in stickymailserver:

您可以在stickymailserver中找到用C#.NET编码的非常基本的SMTP服务器:

Sticky Mail Server is a low-interaction SMTP Honeypot designed to emulate a open SMTP relay. It captures and logs probe messages and mass mailings and saves them for later analysis.

Sticky Mail Server是一种低交互SMTP Honeypot,旨在模拟开放的SMTP中继。它捕获并记录探测消息和群发邮件,并将其保存以供以后分析。

#3


You could use an externally hosted SMTP server. I have found that a lot of email system will block access if the originating SMTP server is behind a dynamic IP address (like most residential systems).

您可以使用外部托管的SMTP服务器。我发现,如果原始SMTP服务器位于动态IP地址之后(如大多数住宅系统),很多电子邮件系统都会阻止访问。

I had to do this recently.

我最近不得不这样做。

 SmtpClient smtp = new SmtpClient("smtp.myserver.com");
 smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
 smtp.Credentials = new System.Net.NetworkCredential("Username", "Password");

Using the "SendCompleted" event, you can send the email in the background without delaying the application.

使用“SendCompleted”事件,您可以在后台发送电子邮件而不会延迟应用程序。

#4


@JoshBerke

I've tried using the below option but receive "Cannot get IIS pickup directory". I know I am pointing to an existing directory, are there permissions I need to set up on the directory?

我尝试使用以下选项,但收到“无法获取IIS拾取目录”。我知道我指向一个现有的目录,我是否需要在目录上设置权限?

<smtp deliveryMethod="SpecifiedPickupDirectory">
     <specifiedPickupDirectory pickupDirectoryLocation="c:\maildrop"/>
</smtp>

#1


As you know SMTP no longer ships with Vista (Which is one of my biggest complaints about Vista). As you already know there are many options out there, and if you found a good free one post a link to it. How you configure it will probally depend on the server you install.

如你所知,SMTP不再附带Vista(这是我对Vista的最大抱怨之一)。你已经知道有很多选择,如果你找到一个好的免费发布链接到它。您如何配置它将取决于您安装的服务器。

I played around with some trial smtp servers, and all the ones I used started listening on the standard SMTP ports on the loopback IP Address. I believe this is the default MailSettings, and shouldn't require any changes.

我玩了一些试用smtp服务器,我使用的所有服务器都开始监听环回IP地址上的标准SMTP端口。我相信这是默认的MailSettings,不应该要求任何更改。

I no longer have any SMTP server and am using the Pickup Directory mode. This causes the mail library to output a file which I can then inspect.

我不再拥有任何SMTP服务器并且正在使用分拣目录模式。这会导致邮件库输出一个我可以检查的文件。

To configure this use the following in your config file:

要配置它,请在配置文件中使用以下内容:

<system.net>
    <mailSettings>
        <smtp deliveryMethod="SpecifiedPickupDirectory">
            <specifiedPickupDirectory
              pickupDirectoryLocation="c:\maildrop"/>
        </smtp>
    </mailSettings>
</system.net>

If you want to configure it to connect to port 25 on your local host you would this for the SMTP section:

如果要将其配置为连接到本地主机上的端口25,则可以使用SMTP部分:

<smtp deliveryMethod="Network">
   <network defaultCredentials="true" host="localhost" port="25"/>
</smtp>

Edit

Terry asked a good question about using the drop location. I only use this for testing, as our production server has an SMTP server which I connect to, and send the email through; however, some SMTP servers can be configured to watch a directory and will pick up and mail anything in there.

特里问了一个关于使用掉落位置的好问题。我只使用它进行测试,因为我们的生产服务器有一个我连接的SMTP服务器,并通过以下方式发送电子邮件;但是,某些SMTP服务器可以配置为监视目录,并将拾取并邮寄其中的任何内容。

I don't think this feature was meant to be used only for testing but it works nicely. The files that get generated can be opened in various mail clients so you can see how they would render them. I belive they .eml files but I can't remember.

我认为这个功能不仅仅用于测试,但效果很好。生成的文件可以在各种邮件客户端中打开,这样您就可以看到它们如何呈现它们。我相信他们的.eml文件,但我不记得了。

#2


You can find a very basic SMTP server coded in C# .NET in stickymailserver:

您可以在stickymailserver中找到用C#.NET编码的非常基本的SMTP服务器:

Sticky Mail Server is a low-interaction SMTP Honeypot designed to emulate a open SMTP relay. It captures and logs probe messages and mass mailings and saves them for later analysis.

Sticky Mail Server是一种低交互SMTP Honeypot,旨在模拟开放的SMTP中继。它捕获并记录探测消息和群发邮件,并将其保存以供以后分析。

#3


You could use an externally hosted SMTP server. I have found that a lot of email system will block access if the originating SMTP server is behind a dynamic IP address (like most residential systems).

您可以使用外部托管的SMTP服务器。我发现,如果原始SMTP服务器位于动态IP地址之后(如大多数住宅系统),很多电子邮件系统都会阻止访问。

I had to do this recently.

我最近不得不这样做。

 SmtpClient smtp = new SmtpClient("smtp.myserver.com");
 smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
 smtp.Credentials = new System.Net.NetworkCredential("Username", "Password");

Using the "SendCompleted" event, you can send the email in the background without delaying the application.

使用“SendCompleted”事件,您可以在后台发送电子邮件而不会延迟应用程序。

#4


@JoshBerke

I've tried using the below option but receive "Cannot get IIS pickup directory". I know I am pointing to an existing directory, are there permissions I need to set up on the directory?

我尝试使用以下选项,但收到“无法获取IIS拾取目录”。我知道我指向一个现有的目录,我是否需要在目录上设置权限?

<smtp deliveryMethod="SpecifiedPickupDirectory">
     <specifiedPickupDirectory pickupDirectoryLocation="c:\maildrop"/>
</smtp>