Send emails via objMessage Function (ASP)
This code I have used to send emails from pages like contact.asp
- Config for Function (incude in global config file or header)
<% ConfigMailActive = "true" ConfigMailUsername = "mail" ConfigMailPassword = "password" configMailServer = "mail.server" ConfigMailPort = cint("25") %>
- Function (Include in global function file or header)
<% Function SendEmail(FEmailTo,FEmailFrom,FEmailSub,FEmailMsg) Set objMessage = CreateObject("CDO.Message") objMessage.Subject = FEmailSub objMessage.From = FEmailFrom objMessage.To = FEmailTo objMessage.htmlBody = FEmailMsg '==This section provides the configuration information for the remote SMTP server. objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1 'Name or IP of Remote SMTP Server objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = configMailServer 'Type of authentication, NONE, Basic (Base64 encoded), NTLM objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoencoded 'Your UserID on the SMTP server objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/sendusername") = ConfigMailUsername 'Your password on the SMTP server objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = ConfigMailPassword 'Server port (typically 25) objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = ConfigMailPort 'Use SSL for the connection (False or True) objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False 'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server) objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60 objMessage.Configuration.Fields.Update '==End remote SMTP server configuration section== IF ConfigMailActive="true" then objMessage.Send End IF set objMessage = nothing End Function %>
- Place at point of email
<% StoreETo = "email@address.co.uk" StoreEFrom = "email@address.co.uk" StoreESubject = "Subject of email" StoreEmsg = "Message String" call SendEmail(StoreETo,StoreEFrom,StoreESubject,StoreEmsg) %>