我有一个asp页面,通过电子邮件使用CDO发送表单的详细信息。到目前为止,我已经通过与hmail服务器的明确连接使用smtp端口25来完成此操作。
我现在需要使用SSL连接。我已创建安全证书并将hmail服务器设置为使用端口465和ssl。
但是,出于某种原因,当我尝试发送表单时,我收到错误500并且未发送电子邮件。
我也尝试使用端口587,但它也不起作用。
我使用的CDO代码如下:
If request.Form("submit") <> "" then
Set myMail=CreateObject("CDO.Message")
myMail.Subject="xxxxxxx"
myMail.From=Request.Form("email")
myMail.To= "xxxxxxxxxxx"
myMail.TextBody = "Name:"& Request.Form("name")& vbcrlf & vbcrlf & _
"Email:" & Request.Form("email") & vbcrlf & vbcrlf & _
"Telephone:" & Request.Form("telephone") & vbcrlf & vbcrlf & _
"Location:" & Request.Form("location") & vbcrlf & vbcrlf & _
"Other location:" & Request.Form("other_location") & vbcrlf & vbcrlf & _
"Comments:" & Request.Form("comments")
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
'Name or IP of remote SMTP server
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") _
="127.0.0.1"
'Server port
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") _
=465
MyMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
myMail.Configuration.Fields.Update
myMail.Send
set myMail=nothing
有没有人知道什么是错的?
谢谢。
答案 0 :(得分:5)
使用旧版ASP代码时遇到了同样的问题。以下代码适用于亚马逊。 注意:只有端口25或465似乎工作且smtpusessl = 1(在VBScript中真== - 1)
' Create Connection
Function GetEmailConnection ()
Set oMail = CreateObject("CDO.Message")
Set GetEmailConnection = oMail
End function
Function GetConfiguration()
Set oConfig = CreateObject("CDO.Configuration")
Set GetConfiguration = oConfig
End Function
' Send Email
Sub SendEmail (subject, fromAddress, toAddress, body)
set objMessage = GetEmailConnection()
Set objConfiguration = GetConfiguration()
Set fields = objConfiguration.Fields
Const cdoSendUsingPort = 2
With fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "email-smtp.us-east-1.amazonaws.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 '
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "user"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
.Update
End With
With objMessage
set .Configuration = objConfiguration
.Subject = subject
.From = fromAddress
.To= toAddress
.TextBody = body
.Send
End With
set objMessage = nothing
end Sub
答案 1 :(得分:0)
这篇文章有点老了,你已经解决了吗?
如果没有,是否可以提供错误消息(通用500除外)?
我只有2个可能的想法而没有看到实际的错误消息:
1)可能会超时。尝试添加myMail.Configuration.Fields.Item _ (“http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout”)= 60
2)或许证书与“127.0.0.1”IP地址不匹配,因此SSL通信被拒绝。