⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webmailprofile.cs

📁 CRM管理系统 CRM管理系统
💻 CS
📖 第 1 页 / 共 2 页
字号:
        {
            ///打开链接
            myConnection.Open();
            ///读取数据
            dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
        }
        catch (SqlException ex)
        {
            ///抛出异常
            throw new Exception(ex.Message, ex);
        }
        ///返回DataReader
        return dr;
    }

    public int SenderMail(MailMessage mail)
    {
        SqlDataReader dr = GetWebMailProfile();

        string ServerIP = "";
        string UserName = "";
        string UserPwd = "";
        int UserPort = 25;

        if (dr.Read())
        {

            ServerIP = dr["MailServerIP"].ToString();
            UserName = dr["UserName"].ToString();
            UserPwd = dr["UserPwd"].ToString();
            UserPort = Convert.ToInt32(dr["MailServerPort"].ToString());

        }
        ///定义发送邮件的Client
        SmtpClient client = new SmtpClient();
        ///设置邮件服务器主机的IP地址
        //client.Host = ((WebMailProfile)HttpContext.Current.Application["WebMailProfile"]).MailServerIP;

        client.Host = ServerIP;


        ///设置邮件服务器的端口
        //client.Port = ((WebMailProfile)HttpContext.Current.Application["WebMailProfile"]).MailServerPort;
        client.Port = Convert.ToInt32(UserPort);
        ///配置发送邮件的属性
        client.DeliveryMethod = SmtpDeliveryMethod.Network;
        client.UseDefaultCredentials = false;
        client.Credentials = new System.Net.NetworkCredential(UserName, UserPwd);
        ///发送邮件
        client.Send(mail);
        return (0);
    }

    public int SaveAsMail(string sTitle, string sBody, string sFrom, string sTo,
        string sCC, bool bHtmlFormat, int nContain, bool bAttachmentFlag)
    {
        ///创建链接
        SqlConnection myConnection = new SqlConnection(ConfigurationManager.AppSettings["connectionString"].ToString());

        SqlCommand myCommand = new SqlCommand("Pr_SaveAsMail", myConnection);
        myCommand.CommandType = CommandType.StoredProcedure;
        ///添加存储过程的参数
        SqlParameter pTitle = new SqlParameter("@Title", SqlDbType.VarChar, 200);
        pTitle.Value = sTitle;
        myCommand.Parameters.Add(pTitle);
        SqlParameter pBody = new SqlParameter("@Body", SqlDbType.Text, 2147483647);
        pBody.Value = sBody;
        myCommand.Parameters.Add(pBody);
        SqlParameter pFrom = new SqlParameter("@FromAddress", SqlDbType.Text, 2147483647);
        pFrom.Value = sFrom;
        myCommand.Parameters.Add(pFrom);
        SqlParameter pTo = new SqlParameter("@ToAddress", SqlDbType.Text, 2147483647);
        pTo.Value = sTo;
        myCommand.Parameters.Add(pTo);
        SqlParameter pCC = new SqlParameter("@CCAddress", SqlDbType.Text, 2147483647);
        pCC.Value = sCC;
        myCommand.Parameters.Add(pCC);

        SqlParameter pHtmlFormat = new SqlParameter("@HtmlFormat", SqlDbType.Bit, 1);
        pHtmlFormat.Value = bHtmlFormat.ToString();
        myCommand.Parameters.Add(pHtmlFormat);
        SqlParameter pContain = new SqlParameter("@Contain", SqlDbType.Int, 4);
        pContain.Value = nContain;
        myCommand.Parameters.Add(pContain);
        SqlParameter pAttachmentFlag = new SqlParameter("@AttachmentFlag", SqlDbType.Bit, 1);
        pAttachmentFlag.Value = bAttachmentFlag.ToString();
        myCommand.Parameters.Add(pAttachmentFlag);

        SqlParameter pMailID = new SqlParameter("@MailID", SqlDbType.Int, 4);
        pMailID.Direction = ParameterDirection.ReturnValue;
        myCommand.Parameters.Add(pMailID);

        ///定义返回值
        int nResult = -1;

        try
        {
            ///打开链接
            myConnection.Open();
            ///执行SQL语句
            nResult = myCommand.ExecuteNonQuery();
        }
        catch (SqlException ex)
        {
            ///抛出异常
            throw new Exception(ex.Message, ex);
        }
        finally
        {   ///关闭链接
            myConnection.Close();
        }
        ///返回nResult
        return (int)myCommand.Parameters[8].Value;
    }

    public int SaveAsMailAttachment(string sName, string sUrl, string sType,
        int nContain, int nMailID)
    {
        ///创建链接
        SqlConnection myConnection = new SqlConnection(ConfigurationManager.AppSettings["connectionString"].ToString());

        ///定义SQL语句
        string cmdText = "INSERT INTO Attachments (Name,Url,Type,Contain,MailID)VALUES("
            + "'" + sName + "',"
            + "'" + sUrl + "',"
            + "'" + sType + "',"
            + "'" + nContain.ToString() + "',"
            + "'" + nMailID.ToString() + "'"
            + ")";
        ///创建Command
        SqlCommand myCommand = new SqlCommand(cmdText, myConnection);

        ///定义返回值
        int nResult = -1;

        try
        {
            ///打开链接
            myConnection.Open();
            ///执行SQL语句
            nResult = myCommand.ExecuteNonQuery();
        }
        catch (SqlException ex)
        {
            ///抛出异常
            throw new Exception(ex.Message, ex);
        }
        finally
        {   ///关闭链接
            myConnection.Close();
        }
        ///返回nResult
        return nResult;
    }

    public int MoveMail(int nMailID, int nFolderID)
    {
        ///创建链接
        SqlConnection myConnection = new SqlConnection(ConfigurationManager.AppSettings["connectionString"].ToString());

        SqlCommand myCommand = new SqlCommand("Pr_MoveMail", myConnection);
        myCommand.CommandType = CommandType.StoredProcedure;
        ///添加存储过程的参数
        SqlParameter pMailID = new SqlParameter("@MailID", SqlDbType.Int, 4);
        pMailID.Value = nMailID;
        myCommand.Parameters.Add(pMailID);

        SqlParameter pFolderID = new SqlParameter("@FolderID", SqlDbType.Int, 4);
        pFolderID.Value = nFolderID;
        myCommand.Parameters.Add(pFolderID);

        ///定义返回值
        int nResult = -1;

        try
        {
            ///打开链接
            myConnection.Open();
            ///执行SQL语句
            nResult = myCommand.ExecuteNonQuery();
        }
        catch (SqlException ex)
        {
            ///抛出异常
            throw new Exception(ex.Message, ex);
        }
        finally
        {   ///关闭链接
            myConnection.Close();
        }
        ///返回nResult
        return nResult;
    }

    public int DeleteMail(int nMailID)
    {
        ///创建链接
        SqlConnection myConnection = new SqlConnection(ConfigurationManager.AppSettings["connectionString"].ToString());

        SqlCommand myCommand = new SqlCommand("Pr_DeleteMail", myConnection);
        myCommand.CommandType = CommandType.StoredProcedure;
        ///添加存储过程的参数
        SqlParameter pMailID = new SqlParameter("@MailID", SqlDbType.Int, 4);
        pMailID.Value = nMailID;
        myCommand.Parameters.Add(pMailID);

        ///定义返回值
        int nResult = -1;

        try
        {
            ///打开链接
            myConnection.Open();
            ///执行SQL语句
            nResult = myCommand.ExecuteNonQuery();
        }
        catch (SqlException ex)
        {
            ///抛出异常
            throw new Exception(ex.Message, ex);
        }
        finally
        {   ///关闭链接
            myConnection.Close();
        }
        ///返回nResult
        return nResult;
    }

    public SqlDataReader GetAttachmentsByMail(int nMailID)
    {
        ///创建链接
        SqlConnection myConnection = new SqlConnection(ConfigurationManager.AppSettings["connectionString"].ToString());
        ///定义SQL语句
        string cmdText = "SELECT * FROM Attachments WHERE MailID='" + nMailID.ToString() + "'";
        ///创建Command
        SqlCommand myCommand = new SqlCommand(cmdText, myConnection);

        ///定义DataReader
        SqlDataReader dr = null;
        try
        {
            ///打开链接
            myConnection.Open();
            ///读取数据
            dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
        }
        catch (SqlException ex)
        {
            ///抛出异常
            throw new Exception(ex.Message, ex);
        }
        ///返回DataReader
        return dr;
    }

    #endregion
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -