html代码:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>JMail发送邮件系统</title> <style type="text/css"> <!-- .STYLE1 {font-size: 18px} --> </style> </head> <body> <form id="form1" name="form1" method="post" action="6.asp"> <table width="570" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#F3F3F3"> <tr> <td colspan="2" bgcolor="#F8D8D1" align="center" class="STYLE1">发送邮件</td> </tr> <tr> <td align="center">发送人的姓名</td> <td><input name="fsname" type="text" id="fsname" size="20" maxlength="20" /></td> </tr> <tr> <td align="center">发送人的邮件</td> <td><input name="fsemail" type="text" id="fsemail" size="20" maxlength="20" /></td> </tr> <tr> <td align="center">发送人邮件的密码</td> <td><input name="fspassword" type="password" id="fspassword" size="21" maxlength="20" /></td> </tr> <tr> <td width="194" align="center"> 收件人的邮件</td> <td width="370"><input name="sjemail" type="text" id="sjemail" size="20" maxlength="20" /></td> </tr> <tr> <td align="center">收件人的姓名</td> <td><input name="sjname" type="text" id="sjname" size="20" maxlength="20" /></td> </tr> <tr> <td align="center">邮件主题</td> <td><input name="emailsubject" type="text" id="emailsubject" size="20" maxlength="20" /></td> </tr> <tr> <td align="center">邮件内容</td> <td><textarea name="emailcontent" cols="40" rows="5" id="emailcontent"></textarea></td> </tr> <tr> <td colspan="2" align="center"> <input name="Submit1" type="submit" id="Submit1" value="发 送" onClick=" return check();" /> <input type="reset" name="Submit2" value="重 置" /></td> </tr> </table> </form> </body> </html> <script> function check(){ if(document.form1.fsname.value==""){ alert("请输入发送人的姓名!"); document.form1.fsname.focus(); return false; } var pattern=/^w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*$/; if(!pattern.test(document.form1.fsemail.value)){ alert("请检查发送人的邮件格式是否正确!"); document.form1.fsemail.focus() return false; } if(document.form1.fspassword.value==""){ alert("请输入发送人的密码!"); document.form1.fspassword.focus(); return false; } var pattern=/^w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*$/; if(!pattern.test(document.form1.sjemail.value)){ alert("请检查收件人的邮件格式是否正确!"); document.form1.sjemail.focus() return false; } if(document.form1.sjname.value==""){ alert("请输入收件人的姓名!"); document.form1.sjname.focus(); return false; } if(document.form1.emailsubject.value==""){ alert("请输入邮件主题!"); document.form1.emailsubject.focus(); return false; } if(document.form1.emailcontent.value==""){ alert("请输入邮件内容!"); document.form1.emailcontent.focus(); return false; } } </script>
asp的代码:
<% '获得发送人的姓名 fsname = request.Form("fsname") '获得发送人的邮件地址 fsemail = request.Form("fsemail") '将发送人的邮件地址通过@分离开,放到fs_email数组里面 fs_email = split(fsemail,"@") '获得发送人的邮件密码 fspassword = trim(request.Form("fspassword")) '获得收件人的邮件地址 sjemail = request.Form("sjemail") '获得收件人的姓名 sjname = request.Form("sjname") '获得邮件的主题 emailsubject = request.Form("emailsubject") '获得邮件的内容 emailcontent = request.Form("emailcontent") '设置JMail组件 Set JMail = Server.CreateObject("JMail.Message") '是否将信头编码成iso-8859-1字符集. 缺省是True '邮件的紧急程序,1为最快,5为最慢,3为默认值 Jmail.Priority = 1 JMail.ISOEncodeHeaders = True '如果JMail.silent设置为true,ErrorCode包含的是错误代码 JMail.Silent = True '设置标题和内容编码,如果标题有中文,必须设定编码为gb2312 JMail.Charset = "gb2312" '如果发内嵌附件一定要注释掉这行 'JMail.ContentType = "text/html" '发送人的姓名 JMail.FromName = fsname '发送人的邮件 JMail.From =fsemail '发送人的邮件用户名 JMail.MailServerUserName = fs_email(0) '发送人的邮件密码 JMail.MailServerPassword =fspassword '加入新的收件人 JMail.AddRecipient sjemail, sjname '密件收件人的地址 'JMail.AddRecipientBCC Email '邮件抄送者的地址 'JMail.AddRecipientCC Email '邮件主题 JMail.Subject = emailsubject '邮件内容 JMail.Body = emailcontent '增加一个普通附件 'JMail.AddAttachment(Server.MapPath()) '增加一个嵌入式附件 'The return value of AddAttachment is used as a 'reference to the image in the HTMLBody. 'contentId = JMail.AddAttachment(Server.MapPath("images/email.gif")) '只有HTML格式支持嵌入图片附件,我们采用HTML格式的邮件内容 JMail.HTMLBody = "<html><body><br>"&emailcontent JMail.appendHTML "<br><br></body></html>" '如果对方信箱不支持HTML格式邮件,我们仍需要给他一个友善的提示 JMail.Body = "Too bad you can't read HTML-mail." JMail.appendText " " '执行邮件发送<通过邮件服务器地址>smtp.域名.com 不一定是邮件服务器 if JMail.Send("smtp.163.com") then '我这里是用163邮件服务器在测试 response.Write("邮件发送成功") else response.Write("邮件发送失败") end if JMail.Close() Set JMail = Nothing %> |