![]() | |
|
Sending E-mail on Microsoft IIS
For sites hosted on IIS servers, we support sending emails via Flicks' ocxQmail. For most users, slight modifications to the sample code below should be sufficient. However, for those who want more details on exactly how the emails are sent, take a look at the function syntax, paramaters, And return value sections below. Important: Never create a form that gives the user control of both the FROM and TO addresses. This means that either FROM or TO must be hard-coded into your form script. This could allow someone to use the form for spamming, and is grounds for termination of your hosting account. Sample Code:
<%
Set mailer = Server.CreateObject("ocxQmail.ocxQmailCtrl.1") mailServer = "mail.infoanalytic.com" fromName = "System administrator" fromaddress = "admin@mailer.net" priority = vbNullString returnReceipt = vbNullString toAddressList = "customer197@mailer.net" ccAddressList = "sales@mailer.net" bccAddressList = "admin@mailer.net,loggingaccount@mailer.net" attachmentList = vbNullString messageSubject = "Welcome on board!" messageText = "Welcome to mailer.net" & vbCrLf & _ "We hope you enjoy our services." result = mailer.Q(mailServer, _ fromName, _ fromaddress, _ priority, _ returnReceipt, _ toaddressList, _ ccaddressList, _ bccaddressList, _ attachmentList, _ messageSubject, _ messageText) If result = vbNullString Then Response.Write "mail has been queued." Else Response.Write "mail was not queued, error message is " & result End If %>
Function Syntax
Q(mailServer, _
fromName, _ fromAddress, _ priority, _ returnReceipt, _ toAddressList, _ ccAddressList, _ bccAddressList, _ attachmentList, _ messageSubject, _ messageText) Paramaters
mailServer
Specifies the name of SMTP mail server. Version 3 and above: the mailServer parameter can be a list of multiple
mail serrvers, separated by semicolons, failing over to the next in the list if the previous ones are down or
unavailable.
The special mail server name "<recipient_domain>" represents the mail server associated with the email address
itself. See example below.
Note: Checking the Options/"always try the recipients mail server first" checkbox in the administration dialog
will automatically prepend "<recipient_domain>" on your behalf, allowing existing and new deployments to
seamlessly use this functionality.
fromName
The informal name of the person sending the email message. Can be empty. an error will result if both fromName and fromaddress
Are empty.
fromaddress
The email address of the person sending the email message. Can be empty. an error will result if both fromName and fromaddress
are empty.
priority
The priority of the message. Can be empty or one of "Highest", "High", "Low", "Lowest".
returnReceipt
If empty does nothing. If it has a value of "Yes" then requests a return receipt from the recipients.
toaddressList
The email address of the person to whom the electronic mail message will be sent. Can be empty. multiple recipients
separated by a comma only. an error will result if toAddressList and ccAddressList and bccAddressList are empty.
ccaddressList
The email address of the person to whom the electronic mail message will be carbon-copied. Can be empty. Multiple
recipients separated by a comma only. an error will result if toaddressList and ccaddressList and bccaddressList
Are empty.
bccaddressList
The email address of the person to whom the electronic mail message will be blind carbon-copied. Can be empty.
Multiple recipients separated by a comma only. an error will result if toAddressList and ccAddressList and
bccAddressList are empty.
Attach
The file to be attached. multiple attachments separated by a comma only. Can be empty.
messageSubject
The subject of the message. Can be empty. an error will result if both messageSubject and messageText are empty.
messageText
The text of the message. Can be empty. an error will result if both messageSubject and messageText are empty.
Return Value
Returns an empty string if the message was sent successfully. Otherwise returns a string indicating the error that occurred.
For a complete reference, visit Flicks Software Sending E-mail using the CDO Object on Microsoft IIS
Sample Code:
function sendmail(byval strto,byval strcc,byval
strsubject, byval strbody, byval strattach)
Dim sch, cdoConfig
Dim ObjSendMail
Set ObjSendMail = CreateObject("CDO.Message")
'on error resume next
sch = "http://schemas.microsoft.com/cdo/configuration/"
Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
'Set CDO Port
.Item(sch & "sendusing") = 2
'YOU MUST USE THIS SMTP SERVER INSTEAD OF LOCALHOST
.Item(sch & "smtpserver") = "mail.infoanalytic.com"
.Item(sch & "smtpserverport") = 25
.Item(sch & "smtpconnectiontimeout") = 60
.update
End With
With objsendmail
Set .Configuration = cdoConfig
.From = "billing@4w.com"
.To = strTo
.CC = strCC
'''.BCC = "invoices@4w.com"
.Subject = strsubject
.TextBody = strbody
.AddAttachment(strattach)
if err = 0 then
.Send
if err <> 0 then
errorcode = err
end if
else
errorcode = err
end if
End With
Set objsendmail= Nothing
Set cdoConfig = Nothing
on error goto 0
sendmail = errorcode
response.write err.description
end function
|