Ejemplo n.º 1
0
        public static void SendMailToAllUser(  string subject, string bodytext )
        {
            System.Net.Mail.SmtpClient c = new SmtpClient("mail.cute.edu.tw", 25);
            c.DeliveryMethod = SmtpDeliveryMethod.Network;
            c.Credentials = new System.Net.NetworkCredential("weather", "0988163835");

            SSHMC01Entities db = new SSHMC01Entities();

            foreach (tblUser cust in db.tblUser.Where(n => n.USER_MAIL != null && n.USER_MAIL.Trim() != ""))
            {
            #if DEBUG
                if(!cust.USER_MAIL.ToLower().Contains("ufjl0683"))
                   continue;
            #endif

                MailMessage m_mesg = new MailMessage(new MailAddress("*****@*****.**"), new MailAddress(cust.USER_MAIL));
                m_mesg.Body = bodytext;
                m_mesg.Subject = subject;
                m_mesg.IsBodyHtml = true;
              //  m_mesg.IsBodyHtml = false;
                if (bodytext != "")
                    c.Send(m_mesg);
            }
        }
Ejemplo n.º 2
0
        static bool LogToDB(Message msg,string bodytext)
        {
            string _class;

            if (bodytext.Length > 1000)
                bodytext = bodytext.Substring(0, 1000);
            //msg.Headers.Subject.Contains("大雨") || msg.Headers.Subject.Contains("豪雨") || msg.Headers.Subject.Contains("豪大雨") || msg.Headers.Subject.Contains("強風") || msg.Headers.Subject.Contains("地震")
            if (msg.Headers.Subject.Contains("大雨"))

                _class = "大雨";
            else if (msg.Headers.Subject.Contains("豪雨"))
                _class = "豪雨";
            else if (msg.Headers.Subject.Contains("豪大雨"))
                _class = "豪大雨";
            else if (msg.Headers.Subject.Contains("強風"))
                _class = "強風";
            else if (msg.Headers.Subject.Contains("地震"))
                _class = "地震";
            else if (msg.Headers.Subject.Contains("颱風"))
                _class = "颱風";
            else
                return false;

            WeatherMail.SSHMC01Entities db = new SSHMC01Entities();
            tblPre_disasterNotified rec = new tblPre_disasterNotified()
            {
                ISSEND = false,
                TITLE = msg.Headers.Subject,
                CONTENT = bodytext,
                PRE_ADMONISH_CLASS = _class,
                PUBLISH_ORANG = "中央氣象局",
                TIMESTAMP = DateTime.Now

            };

            db.tblPre_disasterNotified.AddObject(rec);
            db.SaveChanges();
            db.AcceptAllChanges();
            return true;
        }