2/19/10

Using CDO on hostmysite.com with VBscript

If you are still stuck using VBscript (like me) and are using hostmysite.com on their .net servers - then you might find this useful. The standard VBscript email coding doesn't work - so you have to use a hybrid of sorts to get it to run. The code below works well...

Call the Sub - passing in the message you want.



Sub SendEmail(message)

Dim iMsg
Dim iConf
Dim Flds
Dim strHTML
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 iMsg = CreateObject("CDO.Message")
set iConf = CreateObject("CDO.Configuration")

Set Flds = iConf.Fields

' Set the CDOSYS configuration fields to use port 25 on the SMTP server.

With Flds

 .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
 .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail71.safesecureweb.com"
 .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
 .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 15
 .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "root@logsitall.com"
 .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "XXXX"
 .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
 .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False

.Update

End With




' Build HTML for message body.

strHTML =  message

' Apply the settings to the message.
With iMsg
 Set .Configuration = iConf
 .To = "billp@hmc2agency.com"

 .Cc = "wkpatton@aol.com"


 .Sender="admin@logsitall.com"
 .From = "admin@logsitall.com"
 .Subject = "Subject line using sub"
 .HTMLBody = strHTML

End With

iMsg.Send

' Clean up variables.
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing

'MsgBox "Mail Sent!"


End Sub

No comments:

Post a Comment