asp

ASP中怎么发送电子邮件

小亿
93
2024-04-07 10:18:34
栏目: 编程语言

在ASP中发送电子邮件可以使用CDOSYS组件。以下是一个简单的示例代码:

<%
Dim objMail
Set objMail = Server.CreateObject("CDO.Message")

objMail.From = "you@example.com"
objMail.To = "recipient@example.com"
objMail.Subject = "Test Email"
objMail.TextBody = "This is a test email sent from ASP."

objMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.example.com"
objMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMail.Configuration.Fields.Update

objMail.Send

Set objMail = Nothing
%>

在此示例中,我们创建了一个CDOSYS邮件对象objMail,设置了发件人、收件人、主题和内容。然后,我们配置了SMTP服务器和端口,并使用Send方法发送邮件。

请注意,您需要替换示例中的发件人、收件人、SMTP服务器和端口为您自己的信息。此外,您需要确保您的服务器支持CDOSYS组件。

另外,您也可以使用第三方邮件组件,如JMail或ASPEmail,来发送电子邮件,这些组件通常提供更多的功能和选项。

0
看了该问题的人还看了