Ejemplo n.º 1
0
        /// <summary>
        /// 添加邮件到邮件发送队列,支持添加多封邮件
        /// </summary>
        /// <param name="sendingEmailList">邮件发送队列数组</param>
        /// <returns>操作成功标号</returns>
        public int AddEmailToSendingQueue(SendingEmailList[] sendingEmailList)
        {
            int sendingEmailListId = -1;

            //使用全局事务进行控制,保证插入数据的完整性
            using (TransactionScope scope = new TransactionScope())
            {
                foreach (SendingEmailList sendingEmail in sendingEmailList)
                {
                    SqlParameter[] parameters = {
                    new SqlParameter("@emailTitle", SqlDbType.NChar,50),
                    new SqlParameter("@emailContent", SqlDbType.NText),
                    new SqlParameter("@emailAttachmentIds", SqlDbType.NVarChar,200),

                    new SqlParameter("@userName", SqlDbType.NChar,10),
                    new SqlParameter("@emailAddress", SqlDbType.NChar,50),
                     new SqlParameter("@sender", SqlDbType.NChar,10),
                       new SqlParameter("@sendType", SqlDbType.Int,4)
                                                };
                    parameters[0].Value = sendingEmail.emailTitle;
                    parameters[1].Value = sendingEmail.emailContent;
                    parameters[2].Value = sendingEmail.emailAttachmentIds;

                    parameters[3].Value = sendingEmail.userName;
                    parameters[4].Value = sendingEmail.emailAddress;
                    parameters[5].Value = sendingEmail.sender;
                    parameters[6].Value = sendingEmail.sendType;
                    sendingEmailListId = int.Parse(SqlHelper.ExecuteScalar(conn, CommandType.Text,
                        "INSERT INTO usta_SendingEmailList(emailTitle,emailContent,emailAttachmentIds,userName,emailAddress,sender,sendType) VALUES (@emailTitle,@emailContent,@emailAttachmentIds,@userName,@emailAddress,@sender,@sendType);SELECT @@identity;"
                        , parameters).ToString());
                }
                scope.Complete();
            }

            return sendingEmailListId;
        }
Ejemplo n.º 2
0
    //向单个用户发送邮件
    public void SendEmail(string userName, string emailAddress, int type)
    {
        UserCookiesInfo user = BllOperationAboutUser.GetUserCookiesInfo();
        DalOperationAboutEmail dou = new DalOperationAboutEmail();
        SendingEmailList sendingemail = new SendingEmailList();
        if (type == 1)//少量发送邮件
        {
            sendingemail.emailTitle = txtTitle.Text.Trim();
            sendingemail.emailContent = Textarea1.Value.Trim();

        }
        else //向用户组发送邮件
        {
            sendingemail.emailTitle = txtEmailTitle.Text.Trim();
            sendingemail.emailContent = Textarea2.Value.Trim();
        }
        sendingemail.emailAttachmentIds = hidAttachmentId.Value;
        sendingemail.userName = userName;
        sendingemail.emailAddress = emailAddress;
        sendingemail.sender = ConfigurationManager.AppSettings["briefSysName"];
        SendingEmailList[] sendingEmailList = { sendingemail };
        dou.AddEmailToSendingQueue(sendingEmailList);//插入邮件列表
    }