% ' Sample ASP code to send mail using CDO for Windows 2000 ' References (more are further below): ' http://msdn.microsoft.com/en-us/library/ms978698.aspx ' http://msdn.microsoft.com/en-us/library/ms527568.aspx ' http://msdn.microsoft.com/en-us/library/ms527525.aspx ' Putting the Configuration Object in the ASP Session ' http://msdn2.microsoft.com/en-us/library/ms526308.aspx Dim Subject, HTMLBody, TextBody, ErrorDescription Call CreateMessageBody Call SendEmail Sub CreateMessageBody ' These can be named anything so long as they're referenced correctly when actually sending the mail (further below) Subject = "Test message using CDO for Windows 2000" ' If you're not going to send your message in HTML format, then the HTMLBody ' can be skipped here and when the message is actually sent (further below). HTMLBody = "" & vbcrlf _ & "" & vbcrlf & "
" & vbcrlf & "This should be in HTML format, but will " _ & "display an auto-rendered plain-text format for email clients that can't read it correctly. " _ & "The auto-rendered plain-text is ok for basic HTML content, but the TextBody option " _ & "should be used in conjunction with HTMLBody to display a better-formatted plain-text " _ & "portion of the message when the email client doesn't support HTML-formatted messages.
" _ & "" & vbcrlf & "" TextBody = "This is the body of the message in plain-text. If TextBody and HTMLBody are BOTH used, " _ & "the TextBody value will override the auto-rendered plain-text portion of the HTML-formatted " _ & "email when the email client doesn't support HTML-formatted messages." End Sub Sub SendEmail ' Connect to the mail server and send the mail %> <% ' http://msdn.microsoft.com/en-us/library/ms527568.aspx Dim iMsg, iConf Set iMsg = Server.CreateObject("CDO.Message") Set iConf = iMsg.Configuration ' http://msdn.microsoft.com/en-us/library/ms526318.aspx With iConf.Fields .Item(cdoSendUsingMethod) = cdoSendUsingPort ' http://msdn.microsoft.com/en-us/library/ms526994.aspx .Item(cdoSMTPServer) = "smtp.example.com" ' http://msdn.microsoft.com/en-us/library/ms527294.aspx ' .Item(cdoSMTPConnectionTimeout) = 45 ' http://msdn.microsoft.com/en-us/library/ms527325.aspx .Update End With ' http://msdn.microsoft.com/en-us/library/ms526453.aspx With iMsg ' Email address fields (To, Cc, Bcc, From) are formatted like the following: ' (don't forget to escape double-quotes) ' "John Doe"Your message was NOT sent:
Error: <%=ErrorDescription%>