示例#1
0
        public static string SendEmailToGroup(string body, string subject, string group, string attachment = "")
        {
            SmtpClient client = new SmtpClient();
            string strMessage = string.Empty;
            MailMessage msg = new MailMessage();

            // Populate the SmtpClient and MailMessage with the setting in the Web.config

            GetMailSettings(client, msg);

            // get selected group emails
            EmailGroupsBL bl = new EmailGroupsBL();
            foreach (var item in bl.GetEmailReceiver(group))
            {
                msg.To.Add(new MailAddress(item.Name));
            }

            msg.Subject = subject;
            msg.IsBodyHtml = true;
            msg.Body = body;
            if (!string.IsNullOrEmpty(attachment))
            {
                msg.Attachments.Add(new Attachment(attachment));
            }

            try
            {
                client.Send(msg);
                return strMessage;
            }
            catch (Exception ex)
            {
                //throw ex;
                return ex.Message;
            }
        }
示例#2
0
        public static void SendEmailToSelectedGroup(string body, string subject, string attachment = "")
        {
            SmtpClient client = new SmtpClient();

            MailMessage msg = new MailMessage();

            // Populate the SmtpClient and MailMessage with the setting in the Web.config

            GetMailSettings(client, msg);

            // get selected group emails
            EmailGroupsBL bl = new EmailGroupsBL();
            foreach (var item in bl.GetEmailReceiver())
            {
                msg.To.Add(new MailAddress(item.Name));
            }

            msg.Subject = subject;
            msg.IsBodyHtml = true;
            msg.Body = body;
            if (!string.IsNullOrEmpty(attachment))
            {
                msg.Attachments.Add(new Attachment(attachment));
            }
            EmailQueBL queBl = new EmailQueBL();

            tblEmailQue que = new tblEmailQue();

            que.Name = subject;
            que.SendTime = DateTime.Now;
            que.IsSent = false;

            try
            {
                if (!queBl.IsTodayEmailSent())
                {
                    client.Send(msg);
                    que.IsSent = true;
                }

            }
            catch (Exception ex)
            {
                //throw ex;
            }
            finally
            {
                queBl.AddEmailQue(que);
            }
        }