Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 379
  • Last Modified:

Using CDO with VB Script

Can someone please give a sample VB Script using CDO as the method of sending out an email? Using Outlook object will not work for me (can't get by the security prompt).

Thanks,
Ben
0
brclaveria
Asked:
brclaveria
2 Solutions
 
bruintjeCommented:
Hi brclaveria,

you could look at
source: http://www.paulsadowski.com/WSH/cdo.htm

hope this helps a bit
bruintje
0
 
blandyukCommented:
Should be what your looking for. Assuming you have a mail server installed to localhost, if not you can specify an IP address and use authentication.

<%
Function SendEmail(sFrom, sTo, sCc, sBcc, sSubject, sBody)
      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 cdoNone                   = 0
      Const cdoSendUserName           = "http://schemas.microsoft.com/cdo/configuration/sendusername"
      Const cdoSendPassword           = "http://schemas.microsoft.com/cdo/configuration/sendpassword"

      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)            = "localhost"
        .Item(cdoSMTPServerPort)        = 25
        .Item(cdoSMTPConnectionTimeout) = 10
        .Item(cdoSMTPAuthenticate)      = cdoNone
        .Update
      End With

      Set objMessage = Server.CreateObject("CDO.Message")
      Set objMessage.Configuration = objConfig
      
      SendEmail = ""      
      On Error Resume Next
      With objMessage
        .To       = sTo
        If Not IsNull(sCc) Then .Cc      = sCc
        If Not IsNull(sBcc) Then .Bcc      = sBcc
        .From     = sFrom
        .Subject  = sSubject
        .TextBody = sBody
        '.HTMLBody = "<html><body><p>" & Replace(sBody, vbCrLf, "<br>") & "</p></body></html>"
        .Send
      End With
      If Err.Number <> 0 Then
            SendEmail = CStr(Err.Number) & ": " & Err.Description
            Err.Clear
      End If
      On Error Goto 0
      
      Set Fields = Nothing
      Set objMessage = Nothing
      Set objConfig = Nothing
End Function
%>
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now