示例#1
0
 /// <summary>
 /// 发邮件
 /// </summary>
 public void FaYouJian(string title, string body, string toemail)
 {
     try
     {
         DAL.ShuxingDAL sxdal         = new ShuxingDAL();
         Model.Shuxing  sx            = sxdal.GetModelByCond("sxname='use_sendcloud'");
         bool           use_sendcloud = false;
         if (sx != null && sx.sxvalue != "0")
         {
             use_sendcloud = true;
         }
         if (use_sendcloud)
         {
             string sendcloud_fromemail = sxdal.GetOneFiled("sxvalue", "sxname='sendcloud_fromemail'");
             string sendcloud_api_user  = sxdal.GetOneFiled("sxvalue", $"sxname='sendcloud_api_user'");
             string sendcloud_api_key   = sxdal.GetOneFiled("sxvalue", $"sxname='sendcloud_api_key'");
             string res = Tool.SendMailBySendCloud(sendcloud_fromemail, toemail, title, body, sendcloud_api_user, sendcloud_api_key);
             if (res.Contains("成功"))
             {
             }
             else
             {
                 throw new Exception("sendcloud发邮件出错:" + res);
             }
         }
         else
         {
             Model.Emailset m_fa = GetFaJianXiang();
             if (m_fa == null)
             {
                 throw new Exception("发件配置为空");
             }
             string smtp = m_fa.smtp;
             string from = m_fa.email;
             string to   = toemail;
             string pwd  = m_fa.password;
             Tool.SendMail(title, body, to, from, from, pwd, smtp);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#2
0
        /// <summary>
        /// 取发件箱,cur=1,取完后移到一下位
        /// </summary>
        /// <returns></returns>
        public Model.Emailset GetFaJianXiang()
        {
            List <Model.Emailset> list = GetListArray("");

            if (list.Count == 0)
            {
                return(null);
            }
            if (list.Count == 1)
            {
                return(list[0]);
            }
            Model.Emailset m = list.Where <Model.Emailset>(a => a.cur == 1).FirstOrDefault();
            if (m == null)
            {
                //没有cur=1的,取第一个,设置下一个cur=1
                UpdateByCond("cur=1", $"id={list[1].id}");
                return(list[0]);
            }
            else
            {
                //返回,设置 下一个cur=1
                UpdateByCond("cur=0", "1=1");
                int index = list.IndexOf(m);
                index++;
                if (index < list.Count)
                {
                    UpdateByCond("cur=1", $"id={list[index].id}");
                }
                else
                {
                    UpdateByCond("cur=1", $"id={list[0].id}");
                }
                return(m);
            }
        }