Archive for March, 2010

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)
%>

List every ServerVariable stored by the webserver

Normaly added to the bottom of your ASP code (footer.asp) for testing only.


<%
For Each var In Request.ServerVariables
Response.Write var & " = " & Request.ServerVariables(var) & "<br>"
Next
%>

Output is as follows

<span style="font-size: x-small;">ALL_HTTP:<span style="font-size: x-small;">HTTP_ACCEPT<span style="font-size: x-small;">:*/* HTTP_ACCEPT_LANGUAGE:en-gb HTTP_CONNECTION:Keep-Alive HTTP_HOST:mydomain.co.uk HTTP_USER_AGENT:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729) HTTP_COOKIE:ASPSESSIONIDAQSATTBS=BLADACMABJAGMKJPDFPPBONA HTTP_ACCEPT_ENCODING:gzip, deflate
ALL_RAW:Accept: */* Accept-Language: en-gb Connection: Keep-Alive Host: mydomain.co.uk User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729) Cookie: ASPSESSIONIDAQSATTBS=BLADACMABJAGMKJPDFPPBONA Accept-Encoding: gzip, deflate
APPL_MD_PATH:/LM/W3SVC/1/ROOT
APPL_PHYSICAL_PATH:c:\inetpub\wwwroot\
AUTH_PASSWORD:
AUTH_TYPE:
AUTH_USER:
CERT_COOKIE:
CERT_FLAGS:
CERT_ISSUER:
CERT_KEYSIZE:
CERT_SECRETKEYSIZE:
CERT_SERIALNUMBER:
CERT_SERVER_ISSUER:
CERT_SERVER_SUBJECT:
CERT_SUBJECT:
CONTENT_LENGTH:0
CONTENT_TYPE:
GATEWAY_INTERFACE:CGI/1.1
HTTPS:off
HTTPS_KEYSIZE:
HTTPS_SECRETKEYSIZE:
HTTPS_SERVER_ISSUER:
HTTPS_SERVER_SUBJECT:
INSTANCE_ID:1
INSTANCE_META_PATH:/LM/W3SVC/1
LOCAL_ADDR:127.0.0.1
LOGON_USER:
PATH_INFO:/index.asp
PATH_TRANSLATED:c:\inetpub\wwwroot\index.asp
QUERY_STRING:
REMOTE_ADDR:127.0.0.1
REMOTE_HOST:127.0.0.1
REMOTE_USER:
REQUEST_METHOD:GET
SCRIPT_NAME:/index.asp
SERVER_NAME:mydomain.co.uk
SERVER_PORT:80
SERVER_PORT_SECURE:0
SERVER_PROTOCOL:HTTP/1.1
SERVER_SOFTWARE:Microsoft-IIS/5.1
URL:/index.asp
HTTP_ACCEPT:*/*
HTTP_ACCEPT_LANGUAGE:en-gb
HTTP_CONNECTION:Keep-Alive
HTTP_HOST:mydomain.co.uk
HTTP_USER_AGENT:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
HTTP_COOKIE:ASPSESSIONIDAQSATTBS=BLADACMABJAGMKJPDFPPBONA
HTTP_ACCEPT_ENCODING:gzip, deflate