Below is an example of ASP script using CDO to send email:
Line No |
Coding |
1 |
<% |
2 |
Const cdoSendUsingPickup = 1 |
3 |
Const cdoSendUsingPort = 2 |
4 |
Const cdoAnonymous = 0 |
5 |
Const cdoBasic = 1 |
6 |
Const cdoNTLM = 2 |
7 |
Set objMessage = CreateObject("CDO.Message") |
8 |
objMessage.Subject = "Example CDO Message" |
9 |
objMessage.From = "Me" <me@my.com>" |
10 |
objMessage.To = "test@destinated_mailbox.com" |
11 |
objMessage.TextBody = "This is some sample message text.." & vbCRLF & "It was sent using SMTP authentication." |
|
Section 12-20 provides the configuration information for the remote SMTP server |
12 |
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 |
13 |
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.yourdomainname" |
14 |
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic |
15 |
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "your_full_email_address" |
16 |
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "yourpassword" |
17 |
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 |
18 |
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False |
19 |
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60 |
20 |
objMessage.Configuration.Fields.Update |
|
End remote SMTP server configuration section |
21 |
objMessage.Send |
22 |
%> |
Line No |
Explanation |
1 |
Open ASP tag |
2 |
Send message using the local SMTP service pickup directory |
3 |
Send the message using the network (SMTP over the network) |
4 |
Do not authenticate |
5 |
basic (clear-text) authentication |
6 |
NTLM |
7 |
Create the CDO object |
8 |
Subject of the email |
9 |
Sender email address |
10 |
Recipient email address |
11 |
The content of the email |
|
Section 11-19 provides the configuration information for the remote SMTP server |
12 |
Enable CDO to send email using port number (2 = cdoSendUsingPort). This is important if the SMTP server is bind to other port than default port 25 |
13 |
Name or IP of Remote SMTP Server |
14 |
Type of authentication, NONE, Basic (Base64 encoded), NTLM |
15 |
Your UserID on the SMTP server (Your full email address) |
16 |
Your password on the SMTP server |
17 |
Server port (25) - You can choose not to specify the port |
18 |
Use SSL for the connection (False or True) |
19 |
Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server) |
20 |
To save all the configuration set from Line 12 to Line 19 |
|
End remote SMTP server configuration section |
21 |
objMessage.Send |
22 |
Close ASP tag |
Sample Coding:
Article ID: 1640, Created: February 21, 2005 at 10:42 AM, Modified: October 14, 2009 at 4:26 PM