Sending a CDO email message using an SSL connection

我的未来我决定 提交于 2019-12-06 12:05:06

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

This post is a bit old, did you already solve it?

If not, can you provide the error message (other than the generic 500)?

I only have 2 possible ideas without seeing the actual error message:

1) It could be timing out. Try adding myMail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

2) Perhaps there is a certificate mismatch with the "127.0.0.1" IP address and so SSL communications is being refused.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!