2012-10-08 198 views
3

我想用asp.net中的簡單按鈕發送電子郵件。但我得到以下錯誤 - "The transport failed to connect to the server"SMTP服務器名稱和端口

SmtpMail.SmtpServer = "localhost"; 

我用localhost,因爲,我不知道我的電腦的smtp server名.. 我怎樣才能解決這個問題?我怎麼知道SMTP server這個名字?我oswin xp 希望有人能幫助我...

+2

您的計算機上是否安裝了SMTP服務器? – Steve

+0

yup .............. – Sudix

+0

@Sudheesh:SMTP服務器是否正在運行?它是否在標準端口上收聽?你可以檢查SMTP服務器的日誌,看看有沒有什麼有用的東西? – David

回答

1

要測試電子郵件本地建立一個drop folder叫上你的C '信箱':\驅動器,並添加以下到你的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

UPDATE:

您應該使用較新的電子郵件庫...

使用System.Net.Mail;

MailMessage msg = new MailMessage(); 
msg.To = "[email protected]"; 
msg.From = "[email protected]"; 
msg.Subject = "hi"; 
msg.Body = "yes"; 

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

讓我試試..... – Sudix

+0

我沒有得到..相同的錯誤 – Sudix

+0

沒有在maildrop文件夾中?這應該工作...顯示您創建和設置SmtpClient對象和端口屬性的代碼。 – IrishChieftain

0

標準SMTP端口25上運行。如果你沒有什麼你的機器上監聽25端口,那麼你很可能沒有一個SMTP服務器上運行。嘗試:

telnet localhost 25 

並查看是否連接到某物。我並不認爲(即,您在本地主機上沒有SMTP服務器)

0

在執行此操作之前,您的計算機上需要SMTP服務器。

+0

我認爲這可以幫助你。 http://stackoverflow.com/questions/1557989/send-mail-using-localhost-smtp –

+0

你可以使用你的Gmail帳戶來測試它! –

+0

mm .. k ......... – Sudix

相關問題