关于jmail+asp发送邮件的问题
代码我就不贴了。我想知道是不是可以在邮件的正文里包含某一个网页。
还有就是我在发送html邮件的时候总是发送不成功 添加附件也出错。
[解决办法]
可以,但要注意,如果要输出 ",在asp里面就是 " "
如:
<%
mainbody= " <!DOCTYPE HTML PUBLIC " "-//W3C//DTD HTML 4.01 Transitional//EN " " " "http://www.w3.org/TR/html4/loose.dtd " ">
"
%>
[解决办法]
<%@LANGUAGE= "VBSCRIPT " CODEPAGE= "936 "%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml "> <style type= "text/css ">
<!--
body,td,th {
font-size: 14px;
color: #990000;
}
-->
</style>
<%
company_name = replace(request.Form( "company_name "), ", ", ", ")
lxr = replace(request.Form( "lxr "), ", ", ", ")
tel1 = replace(request.Form( "tel1 "), ", ", ", ")
tel2 = replace(request.Form( "tel2 "), ", ", ", ")
email = request.Form( "email ")
password = request.Form( "password ")
center = replace(request.Form( "center "), ", ", ", ")
date_time = now()
if company_name = " " then
response.Write( "公司名称不能为空! ")
response.end
end if
if lxr = " " then
response.Write( "联系人不能为空! ")
response.end
end if
if tel1 = " " then
response.Write( "联系电话不能为空! ")
response.end
end if
if email = " " then
response.Write( "您的E_mail不能为空! ")
response.end
end if
if center = " " then
response.Write( "留言内容不能为空! ")
response.end
end if
'sql = "insert into message (company_name,lxr,tel1,tel2,email,center,date_time) values ( ' "&company_name& " ', ' "&lxr& " ', ' "&tel1& " ', ' "&tel2& " ', ' "&email& " ', ' "¢er& " ', ' "&date_time& " ') "
'objConn.execute(sql)
'response.Write( "感谢您的留言,我们会尽快与您联系! ")
'response.end
smtpserver= "mail.nivs.cn " '发送邮件所使用的SMTP服务器,例如smtp.163.com,请修改
smtpusername= "msg@nivs.cn " '与SMTP服务器对应的邮箱用户名,请修改
smtppwd= "000111 " '与SMTP服务器对应的邮箱密码,请修改 <br/>
myemail= "sannyhu@nivs.cn " '收件人email
smtpname=lxr '发件人姓名
topic=company_name
mailbody=center& " <p> <p> 联系人: "&lxr& " <p> 联系电话: "&tel1& " "&tel2& " <p> 留言人邮箱: "&email& " <p> 留言时间: "&date_time& " <p> <p> <b> 此邮件不能直接回复! <a taregt= " "_blank " " href= " "mailto: "&email& " " "> 请点该处回复!! </a> </b> "
set jmail= server.CreateObject( "jmail.message ")
jmail.Silent = true
jmail.Charset = "GB2312 "
jmail.ISOEncodeHeaders=false
JMail.ContentType= "text/html "
jmail.Priority = 3
jmail.fromname=smtpname
jmail.from=smtpusername
jmail.subject=topic
jmail.Body =trim(mailbody)
jmail.MailServerUserName =smtpusername
jmail.MailServerPassWord =smtppwd
jmail.AddRecipient trim(myemail)
str=jmail.Send(smtpserver)
if str then
Response.write " <script language=javascript> alert( '邮件成功发送! ');window.history.go(-1); </script> "
else
Response.write " <script language=javascript> alert( '邮件发送失败! ');window.history.go(-1); </script> "
end if
jmail.Close
set jmail = nothing
response.end
%>
[解决办法]
jmail.Body = " <html> ............ </html> "
把网页的源代码贴在引号内就可以啊
jmail.Body = " <html> <head> <meta http-equiv= 'Content-Type ' content= 'text/html; charset=utf-8 ' /> </head> <body style= 'text-align:center; '>
<table width= '430 ' border= '0 ' cellspacing= '0 ' cellpadding= '0 ' style= 'border:1px #ccc solid; '>
<tr> <td height= '50 ' colspan= '4 ' align= 'center '> <b> Request Catalog </b> </td> </tr>
<tr> <td width= '30 '> </td> <td width= '80 ' height= '20 ' align= 'left '> Firstname: </td> <td width= '300 ' align= 'left ' style= 'border:1px #ccc solid; background: #F6F6F6; '> " & fname & " </td> <td width= '30 '> </td> </tr>
<tr> <td height= '10 ' colspan= '4 '> </td> </tr> <tr> <td> </td> <td height= '20 ' align= 'left '> Lastname: </td> <td style= 'border:1px #ccc solid; background: #F6F6F6; text-align:left; '> " & lname & " </td> <td> </td> </tr> <tr> <td height= '10 ' colspan= '4 '> </td> </tr>
<tr> <td> </td> <td height= '20 ' align= 'left '> Company: </td> <td style= 'border:1px #ccc solid; background: #F6F6F6; text-align:left; '> " & company & " </td> <td> </td> </tr>
.......
.......
</table> </body> </html> "
类似这样,代码乱了点,改改看吧
[解决办法]
把网页内容当作邮件内容发送就可以了。
如body= " "
body=body& " <!DOCTYPE html PUBLIC " "-//W3C//DTD XHTML 1.0 Transitional//EN " " " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " ">
"
body=body& " <html xmlns= " "http://www.w3.org/1999/xhtml " "> "
body=body& " <body> "
body=body& "就是这样的 "
body=body& " </body> </html> "
body=body& " <script type= " "text/javascript " "> alert( 'JS也可以包含的 '); </script> "
[解决办法]
<% '======================================================================================
Dim ForUser, FromUser, ForUserEmail, FromUserEmail, SmtpServer
Dim emailTit, emailTxt, FromUserID, FromUserIDPW
emailTit = Request.Form( "emailTit ") '从表单获取email的标题
emailTxt = Request.Form( "emailTxt ") '从表单获取邮件的内容
'==========================以下绿色代码是判断服务器是否支持JMAIL组件
Function IsObjInstalled(strClassString)
On Error Resume Next
IsObjInstalled = False
Err = 0
Dim xTestObj
Set xTestObj = Server.CreateObject(strClassString)
If 0 = Err Then IsObjInstalled = True
Set xTestObj = Nothing
Err = 0
End Function
if not IsObjInstalled( "JMail.Message ") then
Response.write "你所使用的服务器不支持邮件发送! "
Response.End
end if
'==========================================================
if Trim(Request.Form( "action ")) = "确定发送 " then
SmtpServer = Request.Form( "SmtpServer ")
FromUserEmail = Request.Form( "FromUserEmail ")
FromUser = Request.Form( "FromUser ")
ForUserEmail = Request.Form( "ForUserEmail ")
FromUserID = Request.Form( "FromUserID ")
FromUserIDPW = Request.Form( "FromUserIDPW ")
Dim JMail
Set JMail=Server.CreateObject( "JMail.Message ")
JMail.Logging=True
JMail.Charset= "gb2312 "
JMail.ContentType = "text/HTML "
JMail.AddHeader "Originating-IP ", Request.ServerVariables( "REMOTE_ADDR ")
if Request.Form( "smtpPW ") = "1 " then '判断服务器是否需要身份验证
' 身份验证
JMail.MailServerUserName = FromUserID
' 身份验证的用户名
JMail.MailServerPassword = FromUserIDPW
' 身份验证的密码
end if
JMail.From = FromUserEmail '发件人的信箱
JMail.FromName = FromUser '发件人的名字
JMail.Subject = emailTit '邮件的主题
JMail.Body = emailTxt '邮件的内容
'==============================收件人的地址!
JMail.AddRecipient(ForUserEmail) '收件人的地址
JMail.Priority=5 '邮件级别1-5数字越大级别越高---3为普通邮件
JMail.Send(SmtpServer) '红色变量是邮件服务器地址
JMail.Close
Set JMail=nothing
if err then
err.clear
Response.Write " <center> <b> 发信功能已经打开,但因服务器不支持发信或者信箱地址错误,导致信件无法发出! </b> </center> "
Response.End
else
Response.Write " <center> <b> 信件已经发出! </b> </center> "
Response.End
end if
end if %>
<style type= "text/CSS ">
<!--
td {
font-size: 12px;
}
-->
</style>
<body leftmargin= "0 " topmargin= "2 " bgcolor= "#0066CC ">
<form action= " " method= "post " name= "input " target= "_self ">
<table width= "436 " border= "0 " align= "center " bgcolor= "#0066CC " cellpadding= "3 " cellspacing= "1 ">
<tr bgcolor= "#CADBF7 ">
<td width= "154 " align= "right " height= "28 "> 收件人名字: </td>
<td width= "267 " height= "28 " class= "text1 "> <input name= "ForUser " type= "text " value= "我容易么我 " size= "20 ">
</td>
</tr>
<tr bgcolor= "#CADBF7 ">
<td width= "154 " align= "right " height= "28 "> 收件人地址: </td>
<td width= "267 " height= "28 "> <input name= "ForUserEmail " type= "text " size= "20 " maxlength= "50 ">
</td>
</tr>
<tr bgcolor= "#CADBF7 ">
<td width= "154 " align= "right " height= "28 "> 发件人姓名: </td>
<td width= "267 " height= "28 "> <input name= "FromUser " type= "text " value= "今晚在线 " size= "20 ">
</td>
</tr>
<tr bgcolor= "#CADBF7 ">
<td width= "154 " height= "13 " align= "right "> 发
[解决办法]
你把要发送的网页页面生成html作为JMail.Body 的内容进行发送就可以了呀