SMTP服务器名称和端口

时间:2012-10-08 12:22:47

标签: asp.net smtp

我正在尝试使用asp.net中的简单按钮发送电子邮件。但我收到了以下错误 - "The transport failed to connect to the server"

  SmtpMail.SmtpServer = "localhost";

我使用过localhost因为,我不知道我的电脑的smtp server名称.. 我该怎么办呢?我怎么知道SMTP server名字?我的oswin xp 希望有人能帮助我...

3 个答案:

答案 0 :(得分:1)

要在本地测试电子邮件,请在C:\驱动器上设置名为“maildrop”的drop folder,并将以下内容添加到Web.Config文件中:

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

ASP.NET: Using pickup directory for outgoing e-mails

<强>更新

您应该使用较新的电子邮件库...

使用System.Net.Mail;

MailMessage msg = new MailMessage(); 
msg.To = "sudheej.j800@outlook.com"; 
msg.From = "sudheej.j800@gmail.com"; 
msg.Subject = "hi"; 
msg.Body = "yes"; 

SmtpClient smtpClient = new SmtpClient("localhost");
smtpClient.Send(msg);

答案 1 :(得分:0)

标准SMTP在端口25上运行。如果您的计算机上的端口25上没有任何内容,则可能没有运行SMTP服务器。尝试:

telnet localhost 25

并查看是否连接到某物。我不认为(即你在localhost上没有SMTP服务器)

答案 2 :(得分:0)

在此之前,您需要在计算机上安装SMTP服务器。