有一种方法是通过微软自带的CDONTS组件发邮件,用这种方法经常会出现没有权限或是发不出去的问题。

这里给大家介绍另一种方法:

ASP中发送邮件的函数<%
ASP中发送邮件的函数
function SendMail(EmailAddress,Subject,Body)
ASP中发送邮件的函数    
'参数说明:
ASP中发送邮件的函数
    'EmailAddress    收信人地址
ASP中发送邮件的函数
    'Subject        邮件标题
ASP中发送邮件的函数
    'Body            邮件正文
ASP中发送邮件的函数
    dim oMsg,oFields
ASP中发送邮件的函数    
dim FromMail,SmtpServer,SmtpUsername,SmtpPassword
ASP中发送邮件的函数    FromMail 
= "" '发信地址
ASP中发送邮件的函数
    SmtpServer = ""    '发信地址smtp服务器
ASP中发送邮件的函数
    SmtpUsername = ""    '发信地址smtp服务器用户名
ASP中发送邮件的函数
    SmtpPassword = ""    '发信地址smtp服务器密码
ASP中发送邮件的函数
    on error resume next
ASP中发送邮件的函数    
set oMsg = server.createobject("CDO.Message")
ASP中发送邮件的函数    oMsg.From 
= FromMail
ASP中发送邮件的函数    oMsg.
To = EmailAddress
ASP中发送邮件的函数    oMsg.Subject 
= Subject
ASP中发送邮件的函数    oMsg.HTMLBody 
= Body
ASP中发送邮件的函数    
set oFields = oMsg.Configuration.Fields
ASP中发送邮件的函数    oFields(
"http://schemas.microsoft.com/cdo/configuration/sendusing").Value = 2
ASP中发送邮件的函数    oFields(
"http://schemas.microsoft.com/cdo/configuration/smtpserver").Value = SmtpServer
ASP中发送邮件的函数    oFields(
"http://schemas.microsoft.com/cdo/configuration/sendusername").Value = SmtpUsername
ASP中发送邮件的函数    oFields(
"http://schemas.microsoft.com/cdo/configuration/sendpassword").Value = SmtpPassword
ASP中发送邮件的函数    oFields(
"http://schemas.microsoft.com/cdo/configuration/smtpauthenticate").Value = 1
ASP中发送邮件的函数    oFields.Update()
ASP中发送邮件的函数    oMsg.HTMLBodyPart.Charset
="gb2312"
ASP中发送邮件的函数
    oMsg.Send()
ASP中发送邮件的函数    
if err.number<>0 then
ASP中发送邮件的函数        SendMail 
= err.Description
ASP中发送邮件的函数    
else
ASP中发送邮件的函数        SendMail 
= "发送成功"
ASP中发送邮件的函数
    end if
ASP中发送邮件的函数    
set oMsg = nothing
ASP中发送邮件的函数
end function
ASP中发送邮件的函数
ASP中发送邮件的函数
'使用示例:
ASP中发送邮件的函数'
SendMail "somebody@server.com","这里填写邮件标题","这里填写邮件内容"
ASP中发送邮件的函数
%>

相关文章:

  • 2021-12-29
  • 2021-09-30
  • 2022-02-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-19
  • 2022-01-02
  • 2022-12-23
  • 2021-09-23
  • 2021-07-14
相关资源
相似解决方案