<%
response.addHeader "content-type","text/htmlcharset=utf-8"
Sub SendMail
On Error Resume Next
Dim msg
set msg = Server.CreateObject("JMail.Message")
If err<>0 Then
Err.clear
'response.write("Jmail组件没有被安装,请联系系统管理员")
'response.End()
End If
msg.charset="gb2312"
msg.From = "service@qkweb.net"
msg.FromName = "启科网络"
msg.MailServerUserName="service@qkweb.net"
msg.MailServerPassWord="123456"
msg.AddRecipient mailto
msg.Subject = mailtitle
msg.htmlBody = mailbody &vbCrLf
msg.appendText ""&vbCrlf
msg.appendText Now()&vbCrLf
msg.Send("smtp.qq.com")
End Sub
%>
调用方法就是 ,先设置收件人,和内容,再call调用
如:
<%
mailto = "test@qkweb.net"
mailbody = "请问一个网站程序设计的问题"
Call SendMail
%>
<%function SendMail(SMTPServer,SMTPServerUserName,SMTPServerPassword,MailDomain,MailtoAddress,MailtoName,Subject,MailBody,FromName,MailFrom,Priority)
dim JMail, msg
set JMail=Server.CreateObject("JMail.Message")
JMail.Charset="gb2312" '编码
JMail.silent=true '设置为true,JMail不会抛出例外错误.
JMail.ContentType = "text/plain" '邮件正文格式
'JMail.ServerAddress = SMTPServer '用来发送邮件的SMTP服务器(无效)
'指定邮件服务器的地址。可以指定多个服务器,用分号点开。可以指定端口号。
'如果serverAddress保持空白,JMail会尝试解决远程邮件服务器,然后直接发送到服务器上去。
'如:JMail.ServerAddress = &tquomail.mydom.netmail2.mydom.net:2500"
JMail.MailServerUserName = SMTPServerUserName '登录用户名
JMail.MailServerPassWord = SMTPServerPassword '登录密码
JMail.MailDomain = MailDomain '域名(如果用“name@domain.com”这样的用户名登录时,请指明domain.com
JMail.AddRecipient MailtoAddress,MailtoName '收信人
JMail.Subject = Subject '主题
JMail.Body = MailBody '邮件正文(纯文本格式)
JMail.FromName = FromName '发信人姓名
JMail.From = MailFrom '发信人Email
JMail.Priority = Priority '邮件等级12345
msg = JMail.Send(SMTPServer)
JMail.Close
set JMail = nothing
SendMail = msg
end function
%>
jmail,一般的虚拟主机服务商,都是安装的,不需要你安装,(如果你是自己的服务器,是需要安装的,下载jmail后,直接安装即可)。在asp中,请用以下代码:<%
on error resume next
sub SendMail(mailto,subject,msg)
set mail=CreateObject("jmail.Message")
Mail.silent = True
'mail_smtprz=true
mail.Charset ="gb2312"
mail.From =jmail_sender '发件人的邮箱地址
'Mail.ISOEncodeHeaders = False ' 是否进行ISO编码,默认为True
mail.MailDomain=jmail_smtpserver '改成可以正常使用的邮件服务器域名
mail.MailServerUserName = jmail_smtp_user '发件人的邮箱的用户名
mail.MailServerPassWord = jmail_smtp_pass '发件人的邮箱密码
mail.AddRecipient mailto '收件人的邮箱地址
'Mail.ReplyTo = "ct.manager@gmail.com" '回复邮箱
'Mail.SenderName = "青岛畅通网络公司" '发送人姓名
mail.subject=Subject
Mail.Priority = 3
Mail.AddHeader "Originating-IP", Request.ServerVariables("REMOTE_ADDR")
mail.body= msg
On Error Resume Next
mail.Send(jmail_smtpserver) '改成可以正常使用的邮件服务器域名
mail.close()
set mail=nothing
end sub
Sub RecordLog(mailto,subject,msg)
Dim LogFileName,FileObject,Out
LogFileName="MAILLOG.txt"
Set FileObject=Server.CreateObject("SCRIPTING.FILESYSTEMOBJECT")
Set Out=FileObject.OpenTextFile(LogFileName,8,True)
Out.WriteLine("Time : " &Now())
Out.WriteLine("MailTo : " &mailto)
Out.WriteLine("Subject : " &subject)
Out.WriteLine("Content : ")
Out.Write(msg)
Out.WriteLine("----------")
Out.WriteLine()
Out.Close
End Sub
%>
其中的主题,内容,发件人,收件人等,请根据自己的情况修改一下即可。
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)