0% found this document useful (0 votes)
119 views5 pages

CDONTS and IIS SMTP Email Sending

The document provides code samples for sending emails from classic ASP using different methods: 1. Using IIS SMTP and CDONTS.NewMail to send an email. 2. Using IIS SMTP and CDO.Message to send an email with cached configuration. 3. Modifying the previous method to use a remote SMTP server instead of IIS by configuring the CDO.Configuration fields. 4. Using Outlook to compose and send an email.

Uploaded by

Tom Pan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
119 views5 pages

CDONTS and IIS SMTP Email Sending

The document provides code samples for sending emails from classic ASP using different methods: 1. Using IIS SMTP and CDONTS.NewMail to send an email. 2. Using IIS SMTP and CDO.Message to send an email with cached configuration. 3. Modifying the previous method to use a remote SMTP server instead of IIS by configuring the CDO.Configuration fields. 4. Using Outlook to compose and send an email.

Uploaded by

Tom Pan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

Retrieve from internet.

1. IIS SMTP + [Link]


Sub SendMailCDONTS(aTo, Subject, TextBody, aFrom)

Const CdoBodyFormatText = 1

Const CdoBodyFormatHTML = 0

Const CdoMailFormatMime = 0

Const CdoMailFormatText = 1

Dim Message 'As New [Link]

'Create CDO message object

Set Message = CreateObject("[Link]")

With Message

'Set email adress, subject And body

.To = aTo

.Subject = Subject

.Body = TextBody

'set mail And body format

.MailFormat = CdoMailFormatText

.BodyFormat = CdoBodyFormatText

'Set sender address If specified.

If Len(aFrom) > 0 Then .From = aFrom

'Send the message

.Send

End With

End Sub

2. IIS SMTP + [Link]


Sub SendMailCDO(aTo, Subject, TextBody, aFrom)

Const cdoOutlookExvbsss = 2
Const cdoIIS = 1

Dim Message 'As New [Link]

'Create CDO message object

Set Message = CreateObject("[Link]")

With Message

'Load IIS configuration

.[Link] cdoIIS

'Set email adress, subject And body

.To = aTo

.Subject = Subject

.TextBody = TextBody

'Set sender address If specified.

If Len(aFrom) > 0 Then .From = aFrom

'Send the message

.Send

End With

End Sub

Sub SendMailCDOCacheConf(aTo, Subject, TextBody, aFrom)

'cached configuration

Dim Conf ' As New [Link]

If IsEmpty(Conf) Then

Const cdoOutlookExvbsss = 2

Const cdoIIS = 1

Set Conf = CreateObject("[Link]")

[Link] cdoIIS

End If
Dim Message 'As New [Link]

'Create CDO message object

Set Message = CreateObject("[Link]")

With Message

'Set cached configuration

Set .Configuration = Conf

'Set email adress, subject And body

.To = aTo

.Subject = Subject

.TextBody = TextBody

'Set sender address If specified.

If Len(aFrom) > 0 Then .From = aFrom

'Send the message

.Send

End With

End Sub

3. 远程 SMTP + [Link]
修改以上列出函数 SendMailCDOCacheConf 的代码,如下
Sub SendMailCDOCacheConf(aTo, Subject, TextBody, aFrom)

'cached configuration

Dim Conf 'As New [Link]

If IsEmpty(Conf) Then

Const cdoSendUsingPort = 2

Set Conf = CreateObject("[Link]")

With [Link]
.Item("[Link] =
cdoSendUsingPort

.Item("[Link] =
"[Link]"

.Update

End With

End If

Dim Message 'As New [Link]

'Create CDO message object

Set Message = CreateObject("[Link]")

With Message

'Set cached configuration

Set .Configuration = Conf

'Set email adress, subject And body

.To = aTo

.Subject = Subject

.TextBody = TextBody

'Set sender address If specified.

If Len(aFrom) > 0 Then .From = aFrom

'Send the message

.Send

End With

End Sub

4. Outlook
Sub SendMailOutlook(aTo, Subject, TextBody, aFrom)

'Create an Outlook object


Dim Outlook 'As New [Link]

Set Outlook = CreateObject("[Link]")

'Create e new message

Dim Message 'As [Link]

Set Message = [Link](olMailItem)

With Message

'You can display the message To debug And see state

'.Display

.Subject = Subject

.Body = TextBody

'Set destination email address

.[Link] (aTo)

'Set sender address If specified.

Const olOriginator = 0

If Len(aFrom) > 0 Then .[Link](aFrom).Type = olOriginator

'Send the message

.Send

End With

End Sub

You might also like