2006/02/18 | Asp+Jmail发邮件
类别(Asp) | 评论(1) | 阅读(963) | 发表于 23:39
由于接了个项目,里面要用到flash+asp发邮件,所以昨晚研究了一下Jmail,其实很简单,但我用了两个多小时才搞定,以下是代码,希望大家都能成功,对了别忘了要先装Jmail哦,而且版本要对,我用的是JMail45,之前那个版本就怎么也不行!
<%
'flash里传过来的变量
Dim JMail, contentId,firstname,price,quantity,fn,ln,email,tel,country,ingame,allInfo
sn = request.form("sn")
price = request.form("price")
quantity = request.form("quantity")
fn = request.form("fn")
ln = request.form("ln")
email = request.form("email")
tel = request.form("tel")
country = request.form("country")
ingame = request.form("ingame")
GameName = request.form("GameName")

allInfo="serverName="&sn&"<br>"&"price="&price&"<br>"&"quantity="&quantity&"<br>"&"firstname="&fn&"<br>"&"lastname="&ln&"<br>"&"email="&email&"<br>"&"telphone="&tel&"<br>"&"country="&country&"<br>"&"ingame="&ingame

'response.write firstname
Set JMail = Server.CreateObject("JMail.Message")
JMail.Charset = "gb2312" ' 邮件字符集,默认为"US-ASCII"
' JMail.ISOEncodeHeaders = False ' 是否进行ISO编码,默认为True
' 服务器邮箱信息(可用变量方式赋值)
JMail.From = "xt0304@163.com" ' 发送者地址
JMail.FromName = fn ' 发送者姓名
JMail.Subject = "book game card" ' 邮件主题
JMail.MailServerUserName = "xt0304" ' 身份验证的用户名
JMail.MailServerPassword = "817250" ' 身份验证的密码

' 设置优先级,范围从1到5,越大的优先级越高,3为普通
JMail.Priority = 3

JMail.AddHeader "Originating-IP", Request.ServerVariables("REMOTE_ADDR")

' 加入一个收件人【变量email:收件人地址】可以同一语句重复加入多个
JMail.AddRecipient("xutao817250@163.com")

' 加入附件【变量filename:附件文件的绝对地址,确保用户IUSR_机器名有访问的权限】
' 【参数设置是(True)否(False)为Inline方式】
'contentId = JMail.AddAttachment (Server.MapPath("jmail.asp"), True)

' 邮件主体(HTML(注意信件内链接附件的方式))
JMail.HTMLBody = "<html><head><META content=zh-cn http-equiv=Content-Language><meta http-equiv=""Content-Type"" content=""text/html; charset=gb2312""><style type=text/css>A:link { FONT-SIZE: 9pt; TEXT-DECORATION: none; color: #000000}A:visited {FONT-SIZE: 9pt; TEXT-DECORATION: none; color: #666666}A:hover {COLOR: #ff6600; FONT-SIZE: 9pt; TEXT-DECORATION: underline}BODY {FONT-SIZE: 9pt} --></style></head><body><font color=red>邮件正文</font><br><font color=green>邮件正文</font><br><b>邮件正文</b></body></html>"

' 邮件主体(文本部分)
JMail.Body = allInfo

' 发送【调用格式:objJMail.Send([username:password@]SMTPServerAddress[:Port])】
JMail.Send("smtp.163.com")

' 关闭并清除对象
JMail.Close()
Set JMail = Nothing

if err.number<>0 then
response.write "data=发送发送失败!"
else
response.write "data=邮件发送成功!"
end if
%>
0

评论Comments

日志分类
首页[116]
Flash&AS2[56]
FMS[3]
Flex&AS3[5]
Asp[5]
My Works[13]
My Life[34]