|
蓝森林 http://www.lslnet.com 2006年8月25日 8:28
[ASP]关于JMAIL的,大家都可以看下。
JMAIL一直没机会用到,最近刚有要求。所以,就来仔细查看了下。
首先,我搜索了坛子,找到了些代码,然后测试。将通过结果告诉大家。
[code]
<%
smtpid = "root@cnbruce.com" 'SMTP服务器登录用户名
smtpwd = "***********" 'SMTP服务器登录密码
smtpurl = "mail.cnbruce.com" '邮件服务器地址
'以上三行就是你所使用的邮件空间配置问题了:1,支持JMAIL(用阿江探针查看);2,开通SMTP服务(向空间提供商咨询)
fromemail ="cnbruce@gmail.com"
sendemail = "cnbruce@126.com"
username="cnbruce"
topic = "Test Jmail"
mailbody = "Welcome to http://www.cnbruce.com."
'以上几行也很明显,你可以将具体内容替换为上页接受数据。
Set JMail=Server.CreateObject("JMail.Message")
'字符集,缺省为"US-ASCII"
JMail.Charset="gb2312"
'开启错误码
jmail.silent = True
'使用日志
JMail.Logging=True
'以HTML格式发送邮件
JMail.ContentType = "text/html"
'SMTP服务器登录用户名
JMail.MailServerUserName = smtpid
'SMTP服务器登录密码
JMail.MailServerPassword = smtpwd
'发件人的邮件地址
JMail.From= fromemail
'发件人的姓名
JMail.FromName = username
'设定邮件的标题
JMail.Subject = topic
'信件正文
JMail.Body = mailbody
'设置邮件的收件人信箱
JMail.AddRecipient sendemail
'设置邮件的优先级(1-5,1为最高)
JMail.Priority=3
'执行邮件的发送
JMail.send(smtpurl)
JMail.Close()
Set JMail=nothing
%>
<script language="javascript">
alert( "您的邮件已成功递交!")
location.href = "javascript:history.go(-1);"
</script>
[/code]
以上代码,测试通过,并且也收到邮件。我剩下的就是附件的问题了。
有哪位已经解决的?还望指教 :) |
[code]on Error resume next
Set Jmail=server.createobject("Jmail.Message")
if Err.Number<>0 then
errMsg=errMsg&"<br>当前服务器不支持Jmail组件,所以不能发确认信了"
err.clear
else
'path=Server.MapPath("/images/468_03.gif")
Jmail.Logging = true
Jmail.Charset = "gb2312"
Jmail.Encoding = "base64"
'JMail.ContentTransferEncoding = "base64"
Jmail.ContentType ="text/html" 'multipart/mixed
Jmail.Silent = true
Jmail.Priority = 3
Jmail.MailServerUserName = smtpUser '(这里换成您的SMTP验证帐号)
Jmail.MailServerPassword = smtpPassword '(这里填写您的SMTP认证密码)
Jmail.From = classEmail
Jmail.FromName = "心缘地方"
Jmail.Subject = "欢迎您成为天津大学九九化工六班的新成员!"
Jmail.AddRecipient email ' (收信人地址)
Jmail.AddHeader "Originating-IP", Request.ServerVariables("REMOTE_ADDR")
'cID=JMail.AddAttachment(path,true)
mailBody="<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.01 Transitional//EN""> <html> <head> <title>Untitled Document</title> <meta http-equiv=""Content-Type"" content=""text/html; charset=gb2312""> <style type=""text/css""> <!-- body { font-size: 12px; line-height: 150%; color: #FFFFCC; } td { font-size: 12px; line-height: 150%; } a:link { color: #FF9933; text-decoration: none; } a:hover { color: #996600; text-decoration: underline; } a:visited { color: #FFCC00; text-decoration: none; } --> </style> </head> <body bgcolor=""#993333""> <div align=""center"">注册确认信<br> </div> <table width=""500"" border=""0"" align=""center"" cellpadding=""4"" cellspacing=""2""> <tr> <td bordercolor=""#FFFF99"" bgcolor=""#993333""><b><font color=""#FFFFCC"">"& userName &":你好</font></b></td> </tr> <tr> <td bgcolor=""#993333""> 欢迎注册成为"&className&"的新成员。 以下是您的注册信息,请注意保留。</td> </tr> <tr> <td bgcolor=""#993333""><b>账号:"&userName&"<br> 密码:"&replace(trim(request.Form("password")),"'","")&"<br>密码提示问题:"&question&"<br>提示问题答案:"&answer&"</b></td> </tr> <tr> <td bgcolor=""#993333""> 有任何问题可以在班级留言中提出,或给管理员发站内消息(未批准的成员也可以发站内消息),或<a href='mailto:"&classEmail&"'>发信给管理员</a></td> </tr> </table> <div align=""center""><br> <font face=""Verdana, Arial, Helvetica, sans-serif""><b><a href=""http://www.mytju.com"" target=""_blank"">www.mytju.com</a></b></font></div> </body> </html> "
'mailBody=mailBody& "<img src='cid:468_03.gif'>"
'Jmail.HTMLBody = mailBody
Jmail.Body = mailBody
'Jmail.Send(smtpServer)
if not Jmail.Send(smtpServer) then
errMsg=errMsg+"<br>下面是发送Log:<br>"
errMsg=errMsg+"<pre>" & Jmail.log & "</pre>"
else
errMsg=errMsg+"<br>Email发送成功!"
end if
'ErrStr =JMail.errormessage
Jmail.close()
Jmail.ClearAttachments
Set Jmail=nothing
end if 'end of CreateObject[/code]
参考。
Jmail.ContentType ="text/html" 'multipart/mixed
后面的就是了。 |
其实要添加Attachment,主要用到[color=Red]Message.addatachment()[/color]
以下仅供参考:
[color=#808080]
<%
SmtpHost="smtp.126.com"
SmtpUser="hzg139"
SmtpPassword="********"
Set JMail=Server.CreateObject("JMail.Message")
JMail.Silent=TRUE
JMail.CharSet="gb2312"
JMail.From = "hzg139@gmail.com"
Jmail.FromName = "hzg139"
JMail.Subject="HI"
Mailbody="this is a test"
Jmail.body=Mailbody
'========Attachment的思路:先将附件Upload在UPFILE下,然后将路径用session保存(为了管理方便,也可以用数据库),这里省略这步
'========直接从session("attachment")中取得attachment的路径
Attachment=session("attachment")
If Attachment <> "" Then
'这里是添加Attachment的地方
JMail.AddAttachment(Attachment)
JMail.Priority = "3"
If SmtpUser <> "" Then
JMail.MailServerUserName = SmtpUser
If SmtpPass <> "" Then
JMail.MailServerPassword = SmtpPass
If SmtpPass <> "" Then
JMail.Send("SMTPHost")
Else
Response.Write ("<font color=red size=2>错误的密码或没有填写SMTP密码!</font>")
End If
JMail.ClearAttachments
JMail.close
Set JMail=nothing
%>
[/color] |
cnbruce在上个帖子中说
把这些代码放到网页上什么位置,才能实现Email的发送功能呀,我用的是表单做的,如何接收变量呀?有哪位朋友知道呀,我的表单位代码:
feedback.htm代码:
<html>
<head>
<title>feedback</title>
</head>
<body>
<form action="post.asp" method="post" name="mywebmail">
您的姓名:
<input type="text" name="name" size="20" maxlength="50">
电子邮件:
<input type="text" name="email" size="20" maxlength="60">
邮件主题:
<input type="text" name="mailsubject" size="30" maxlength="100">
您的意见和建议:<br>
<textarea rows="4" name="text" cols="40"></textarea>
<input type="submit" value="确认递交" name="submit">
<input type="reset" value="清除重写" name="clear">
</form>
</body>
</html>
还有,邮箱服务器的事
smtpid = "root@cnbruce.com" 'SMTP服务器登录用户名
smtpwd = "***********" 'SMTP服务器登录密码
smtpurl = "mail.cnbruce.com" '邮件服务器地址
这里填写的是接由邮箱的用户名及密码吗,同一个邮箱能能给自己发送邮件吗?
|
|