当前位置:编程学习 > asp >>

高分求asp代码:用户输入email ,系统接收后自动发送邮件到这个email。

做两个页面,不需要连接数据库: 1 接收用户输入email,需要检测输入的email是否正确。 2 系统接收到这个email,自动发一封预先设置好的邮件。
答案:人家要ASP的源代码,楼上的给.NET的。呵呵。
你这个啊,下载一个免费的JMAIL,按照要求安装上。
JMAIL就是常用的发送EMAIL的组件。
然后网上关于JMAIL如何发送邮件的有的是,自己找找。 
给你一段我的参考代码,自己研究研究。要是找人一点不差的做出来给你,没人能回答你的。
'JMAIL发送邮件
Call SendMail()
Sub SendMail()
	On Error Resume Next
	Set JMail=Server.CreateObject("JMail.Message") '创建对象
	If Err Then
		Err.Clear
		Response.Write "邮件发送组件检测失败。"
		JMail.Close()
		Set JMail = Nothing
		Exit Sub
	End If
	JMail.Charset = "gb2312" '邮件字符集(简体中文)
	JMail.ContentType = "text/html" '邮件编码
	JMail.ReturnReceipt = True '是否收条
	JMail.silent = True '忽略错误
	'发送者信息
	JMail.From = "xxx@xxx.com" ' 发送者地址
	JMail.FromName = "王先生" ' 发送者姓名
	'身份验证
	JMail.MailServerUserName = "xxxxx" ' 身份验证的用户名
	JMail.MailServerPassword = "*****" ' 身份验证的密码
	' 邮件的紧急程序,1为最快,5为最慢,3 为默认值
	JMail.Priority = 3
	JMail.AddHeader "Originating-IP", Request.ServerVariables("REMOTE_ADDR")
	'接收者信息
	JMail.AddRecipient("xx@xx.com") '加入一个收件人
	JMail.Subject = "通行证激活邮件" ' 邮件主题
	'邮件主体(html格式)
	MailBody = ""
	MailBody = "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.01 Transitional//EN"">"
	MailBody = MailBody & "<html>"
	MailBody = MailBody & "<head>"
	MailBody = MailBody & "<meta http-equiv=""Content-Type"" content=""text/html; charset=gb2312"">"
	MailBody = MailBody & "<style>"
	MailBody = MailBody & "body,tr,td {font-family:Arial, Helvetica, sans-serif;font-size:14px;color:#3b3b3b;line-height:21px;}"
	MailBody = MailBody & "a:link,a:visited {font-size:14px;color:#0000FF;font-family:Arial, Helvetica, sans-serif;text-decoration:underline;}"
	MailBody = MailBody & "a:hover {font-size:14px;color:#C80700;font-family:Arial, Helvetica, sans-serif;text-decoration:none;}"
	MailBody = MailBody & "</style>"
	MailBody = MailBody & "</head>"

	MailBody = MailBody & "<body bgcolor=""#F9F9F9"" leftmargin=""0"" topmargin=""4"" marginwidth=""0"" marginheight=""0"">"
	MailBody = MailBody & "<table width=""560"" border=""0"" align=""center"" cellpadding=""2"" cellspacing=""1"">"
	MailBody = MailBody & "<tr>"
	MailBody = MailBody & "<td colspan=""2"">尊敬的xxx用户:<br>您好!</td>"
	MailBody = MailBody & "</tr>"
	MailBody = MailBody & "<tr>"
	MailBody = MailBody & "<td width=""40""> </td>"
	MailBody = MailBody & "<td>正文内容</td>"
	MailBody = MailBody & "</tr>"
	MailBody = MailBody & "</table>"
	MailBody = MailBody & "</body>"
	MailBody = MailBody & "</html>"

	JMail.HTMLBody = MailBody

	' 发送【调用格式:objJMail.Send([username:password@]SMTPServerAddress[:Port])】
	JMail.Send("smtp.exmail.qq.com") '发送邮箱的SMTP
	' 关闭并清除对象
	JMail.Close()
	Set JMail = Nothing
End Sub
其他:1.判断邮箱格式。
 <input type="text" id="txtEmail" title="请确认是否为空" name="txtEmail" />
 var MainEmail = $("#txtEmail").val();
                var re = /\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+/g;
                var m = MainEmail.match(re);
                if (m == null) {
                    $("#divEmail").css("display", "block");
                    $("#divEmailClew").css("display", "none");
                    $("#divEmailError").css("display", "none");
                    $("#divEmailSuccess").css("display", "none");
                    return false;
                }
2.发送邮件:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;

public partial class UserReg_register_update : TsingDa.VocationalEdu.Common.PageBase
{
    private static string mailFrom = ConfigurationManager.AppSettings["mailFrom"].ToString();//发送的邮件
    private static string mailSendUserName = ConfigurationManager.AppSettings["mailSendUserName"].ToString();//发送人
    private static string sendpassword = ConfigurationManager.AppSettings["sendpassword"].ToString();//发送密码

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string _Email = GetSecureRequestParamsString("Emial");
            string _UserName = GetSecureRequestParamsString("userName");
            string _Password = GetSecureRequestParamsString("password");
            Response.Write(InsertMainInfomation(_Email, _UserName, _Password)); //
        }
    }

    public int InsertMainInfomation(string email, string username, string password)
    {
        string _validatestring = email + "|" + username + "|" + DateTime.Now.ToString() + "|" + GetVirtualID(4);
        HttpContext.Current.Session["IsEmail"] = _validatestring;//邮箱验证码储存在session中

//这是你预先设定好的邮件
            string emialConent = _GetDataFromInternet("http://www.zhaoxi.net/UserReg/register_confirm-success.html", System.Text.Encoding.Default);

            if (emialConent.Contains("{ss}"))
            {
                emialConent = emialConent.Replace("{ss}", username);
            }
            if (emialConent.Contains("{confim}"))
            {
                emialConent = emialConent.Replace("{confim}", _validatestring);
            }
            TsingDa.VocationalEdu.Email.Email.StartSendMail(email.ToString(), mailFrom, "注册激活邮件", emialConent);
       
            return sun;
    }

    /// <summary>
    /// 获取页面内容
    /// </summary>
    /// <param name="UrlAddress"></param>
    /// <param name="encoding"></param>
    /// <returns></returns>
    private string _GetDataFromInternet(string UrlAddress, System.Text.Encoding encoding)
    {
        string pageurl = System.Web.HttpUtility.UrlEncode(UrlAddress);

        System.Net.WebRequest request = System.Net.WebRequest.Create(System.Web.HttpUtility.UrlDecode(pageurl));
        request.Timeout = 10000;//单位:毫秒
        System.Net.WebResponse response = request.GetResponse();
        System.IO.Stream resStream = response.GetResponseStream();
        System.IO.StreamReader sr = new System.IO.StreamReader(resStream, encoding);
        string result = sr.ReadToEnd();
        resStream.Close();
        sr.Close();
        return result;

    }

    /// <summary>
    /// 生成随机数
    /// </summary>
    /// <param name="len">随机数长度</param>
    /// <returns></returns>
    public static string GetVirtualID(int len)
    {
        char[] s = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N', 'Q', 'W', 'R', 'T', 'Y', 'U', 'O', 'P', 'J', 'S', 'Z', 'X', 'V' };
        string num = "";
        Random r = new Random();
        for (int i = 0; i < len; i++)
        {
            num += s[r.Next(0, s.Length)].ToString();
        }
        return num;
    }
} Mark

上一个:asp 按钮上字体大小如何设置
下一个:ASP单选能否传递多变量

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,