发送电子邮件vbscript asp

时间:2015-05-28 11:57:55

标签: email vbscript asp-classic

我有Windows Server 2012 R2和IIS8.5 我试图通过CDo发送电子邮件

<%

Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory. 
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network). 

Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM

Set objMessage = CreateObject("CDO.Message") 
objMessage.Subject = "Example CDO Message" 
objMessage.From = "mymail@gmail.com" 
objMessage.To = "email@gmail.com" 
objMessage.TextBody = "This is some sample message text.." & vbCRLF & "It was sent using SMTP authentication."

'==This section provides the configuration information for the remote SMTP server.

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 

'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"

'Type of authentication, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic

'Your UserID on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "myemail@gmail.com"

'Your password on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "mypass"

'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 

'Use SSL for the connection (False or True)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False

'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

objMessage.Configuration.Fields.Update

'==End remote SMTP server configuration section==

objMessage.Send
response.write objMessage.Err.number
%>

响应超过84000毫秒,我收到错误

Active Server Pages error 'ASP 0113'

Script timed out

/login.asp

The maximum amount of time for a script to execute was exceeded. You can change this limit by specifying a new value for the property Server.ScriptTimeout or by changing the value in the IIS administration tools.

从VBA发送具有相同代码的相同电子邮件即可,没有任何错误。

有什么问题?

1 个答案:

答案 0 :(得分:2)

在页面顶部,你必须回忆一下libreries:

<!--METADATA TYPE="typelib" UUID="CD000000-8B95-11D1-82DB-00C04FB1625D" NAME="CDO for Windows 2000 Type Library" -->
<!--METADATA TYPE="typelib" UUID="00000205-0000-0010-8000-00AA006D2EA4" NAME="ADODB Type Library" -->
<%@LANGUAGE="VBSCRIPT"%>

然后您可以尝试使用此代码:

Set email_info = CreateObject("CDO.Message")
            Set iConf = CreateObject("CDO.Configuration")
            Set Flds = iConf.Fields
            Flds(cdoSendUsingMethod) = cdoSendUsingPort
            Flds(cdoSMTPServer) = "smtp.domain-name.ext" 
            Flds(cdoSMTPServerPort) = 25
            Flds(cdoSMTPAuthenticate) = cdoAnonymous ' 0
            Flds.Update
            Set email_info.Configuration = iConf