Example #1
0
        public static bool Send(string[] to, string subject, string msg)
        {
            var cfg = MailCfg.GetBaseDirectory();

            try {
                var mail       = new MailMessage();
                var SmtpServer = new SmtpClient(cfg.smtpClient);

                mail.From = new MailAddress(cfg.from);
                for (var i = 0; i < to.Length; i++)
                {
                    mail.To.Add(to[i]);
                }
                mail.Subject    = subject;
                mail.IsBodyHtml = true;
                mail.Body       = GetHtmlMsg(cfg, subject, msg);

                SmtpServer.Port        = cfg.port;
                SmtpServer.Credentials = new System.Net.NetworkCredential(cfg.from, cfg.password);
                SmtpServer.EnableSsl   = cfg.ssl;

                SmtpServer.Send(mail);
                return(true);
            } catch (Exception ex) {
                Console.WriteLine(ex);
                return(false);
            }
        }
Example #2
0
        public static string GetHtmlMsg(MailCfg cfg, string sub, string msg)
        {
            var html = ReadTemplate();

            html = html.Replace("{headerTitle}", sub);
            html = html.Replace("{Subject}", sub);
            html = html.Replace("[\r\n\t]", "");
            html = html.Replace("{Mesage}", msg);
            return(html);
        }