如何在Windows 2008服务器上从ASP应用程序发送电子邮件

问题描述:

我的ASP,传统的ASP应用程序在Windows 2008 Server上给我一个服务器错误。它在Windows 2003服务器上正常工作。该错误是500内部服务器错误。 CDO不适用于Windows 2008吗?如何在Windows 2008服务器上从ASP应用程序发送电子邮件

编辑 错误是:传输失败连接到服务器。

这里是我的邮件功能:

function SendMail(mailFrom, mailTo, mailSubject, mailBody, bHtml) 
Const cdoSendUsingMethod  = _ 
"http://schemas.microsoft.com/cdo/configuration/sendusing" 
Const cdoSendUsingPort   = 2 
Const cdoSMTPServer    = _ 
"http://schemas.microsoft.com/cdo/configuration/smtpserver" 
Const cdoSMTPServerPort   = _ 
"http://schemas.microsoft.com/cdo/configuration/smtpserverport" 
Const cdoSMTPConnectionTimeout = _ 
"http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout" 
Const cdoSMTPAuthenticate  = _ 
"http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" 
Const cdoBasic     = 1 
Const cdoSendUserName   = _ 
"http://schemas.microsoft.com/cdo/configuration/sendusername" 
Const cdoSendPassword   = _ 
"http://schemas.microsoft.com/cdo/configuration/sendpassword" 
Const smtpServer = "localhost" 

Dim objConfig ' As CDO.Configuration 
Dim objMessage ' As CDO.Message 
Dim Fields  ' As ADODB.Fields 

' Get a handle on the config object and it's fields 
Set objConfig = Server.CreateObject("CDO.Configuration") 
Set Fields = objConfig.Fields 

' Set config fields we care about 
With Fields 
.Item(cdoSendUsingMethod)  = cdoSendUsingPort 
.Item(cdoSMTPServer)   = smtpServer 
.Item(cdoSMTPServerPort)  = 25 
.Item(cdoSMTPConnectionTimeout) = 10 
.Item(cdoSMTPAuthenticate)  = cdoBasic 
.Item(cdoSendUserName)   = "username" 
.Item(cdoSendPassword)   = "password" 

.Update 
End With 

Set objMessage = Server.CreateObject("CDO.Message") 

Set objMessage.Configuration = objConfig 

With objMessage 
.To  = mailTo 
.From  = mailFrom 
.Subject = mailSubject 
if bHtml then 
.HtmlBody = mailBody 
else  
.TextBody = mailBody 
end if 
.Send 
End With 

Set Fields = Nothing 
Set objMessage = Nothing 
Set objConfig = Nothing 

end function 
+0

从ASP应用程序Windows 2008服务器发送电子邮件有哪些选项? – Picflight 2009-08-06 00:25:10

看来,CDO/MAPI库默认情况下,Windows 2008中未安装:

你可以download them from Microsoft

参考from this blogpost

如果你想编写客户端应用程序 到 使用MAPI或CDO(例如,网络 服务器)和你不想安装 的计算机上运行(或无法安装)Outlook 客户端或Exchange管理 工具,则需要安装 MAPI/CDO库。

+0

链接被破坏,所以这里是新的:http://www.microsoft.com/en-us/download/details.aspx?id=1004 – stare 2013-12-09 21:38:25

+0

从来没有这样做,感谢您的建议! – stare 2013-12-11 17:15:08