在ASP中使用CDOSYS發送電子郵件的步驟如下:
<%
Set objEmail = Server.CreateObject("CDO.Message")
%>
<%
objEmail.From = "sender@example.com"
objEmail.To = "recipient@example.com"
objEmail.Subject = "Sample Email"
objEmail.HTMLBody = "Hello, this is a sample email!"
%>
<%
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.example.com"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "username"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objEmail.Configuration.Fields.Update
%>
請注意替換上述代碼中的SMTP服務器地址、端口號、身份驗證信息等為您實際使用的值。
<%
objEmail.Send
%>
完整的示例代碼如下:
<%
Set objEmail = Server.CreateObject("CDO.Message")
objEmail.From = "sender@example.com"
objEmail.To = "recipient@example.com"
objEmail.Subject = "Sample Email"
objEmail.HTMLBody = "Hello, this is a sample email!"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.example.com"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "username"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objEmail.Configuration.Fields.Update
objEmail.Send
%>
請注意,上述代碼中的SMTP服務器需要提供身份驗證信息,您需要將"username"和"password"替換為您自己的SMTP服務器的用戶名和密碼。此外,還要確保CDOSYS組件已經在服務器上正確安裝和配置。