Följande funktion används för att skicka ett mail med CDO och returnerar True ifall meddelandet skickades och False ifall något fel uppstod.Skicka mail med CDO
<code>
Function sendMail(recipient,sender,subject,message)
Const cdoSendUsingPort = 2
Const cdoBasic = 1
Const cdoSMTPServer = "mySMTPServer.com"
Const cdoUserName = "myUsername"
Const cdoPassword = "myPassword"
On Error Resume Next
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = subject
objMessage.Sender = sender
objMessage.To = recipient
objMessage.TextBody = message
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = cdoSMTPServer
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = cdoUserName
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = cdoPassword
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objMessage.Configuration.Fields.Update
objMessage.Send
Set objMessage = Nothing
sendMail = (err.number = 0)
End Function
</code>