使用SSL连接发送CDO电子邮件 [英] Sending a CDO email message using an SSL connection
问题描述
我有一个ASP页面,该页面使用CDO通过电子邮件发送表单的详细信息.到目前为止,我已经通过与hmail服务器的清晰连接使用smtp端口25进行了此操作.
I have an asp page that sends the details of a form via email using CDO. So far, I have done this using smtp port 25 over a clear connection to a hmail server.
我现在需要使用SSL连接.我已经创建了安全证书,并将hmail服务器设置为使用端口465和ssl.
I now need to use an SSL connection. I have created a security certificate and set hmail server to use port 465 and ssl.
但是,由于某种原因,当我尝试发送表单时,出现错误500,并且电子邮件未发送.
However, for some reason when I try to send the form I get an error 500 and the email is not sent.
我也尝试使用587端口,但是它也不起作用.
I have tried with port 587 as well but it doesn't work either.
我使用的CDO代码如下:
The CDO code I use is as follows:
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
有人知道什么是错的吗?
Does anyone have an idea what can be wrong?
谢谢.
推荐答案
在使用旧版ASP代码时,我遇到了同样的问题.以下代码适用于Amazon. 注意:似乎只有端口25或465可以工作,并且smtpusessl = 1(在VBScript True ==-1中)
I had the same problem working with Legacy ASP Code. The following Code works with Amazon. Note: Only Port 25 or 465 seems to work and smtpusessl = 1 (in VBScript True==-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
这篇关于使用SSL连接发送CDO电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!