Esempio n. 1
0
        public bool SendEmail(string sBody, string sFilePath)
        {
            using (var eh = new EmailHelper(SmtpConnStr))
            {
                eh.AddToAddress(EmailReceiver);
                eh.AddCcAddress(EmailCC);
                if (System.IO.File.Exists(sFilePath))
                {
                    eh.AddAttachment(new System.Net.Mail.Attachment(sFilePath));
                }

                var dt = DateTime.Now;
                eh.Body    = sBody;
                eh.Subject = MakeEmailSubject(dt);
                try
                {
                    eh.SendMail();
                }
                catch (Exception ex)
                {
                    ErrorOut(ex);
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 2
0
        public bool SendMail(string sFileTempl, string sSubject, string sContent, string sTable)
        {
            //send mail
            var sBody = new StringBuilder();

            try
            {
                sBody.Append(System.IO.File.ReadAllText(sFileTempl));
                sBody.Replace("{title}", sSubject);
                sBody.Replace("{content}", sContent);
                sBody.Replace("{tabContent}", sTable);
            }
            catch (Exception ex)
            {
                //LogHelper.WriteError(typeof(CommodityRecv_DAL), ex);
                return(false);
            }

            var eh = new EmailHelper(SmtpConnStr);

            eh.AddToAddress(EmailReceiver);
            eh.AddCcAddress(EmailCC);
            eh.Subject = sSubject;
            eh.Body    = sBody.ToString();

            var bSend = true;

            try
            {
                eh.SendMail();
            }
            catch (Exception ex)
            {
                bSend = false;
            }
            return(bSend);
        }