예제 #1
0
        public static MailMessage Createmessage(DataRow d)
        {
            MailMessage mail     = new MailMessage();
            MailAddress sender   = new MailAddress(ConfigurationManager.AppSettings["smtpUser"]);
            MailAddress receiver = new MailAddress("*****@*****.**");

            mail.From = sender;
            mail.To.Add(receiver);
            SendMailBody sm = new SendMailBody();

            mail.Body       = sm.PopulateBody(d[1].ToString(), d[2].ToString(), d[3].ToString(), d[4].ToString(), d[5].ToString(), d[6].ToString());
            mail.IsBodyHtml = true;
            return(mail);
        }
예제 #2
0
        static void Main(string[] args)
        {
            DataTable csvData = CustomerExcel.ReadCsvFile();

            foreach (DataRow d in csvData.Rows)
            {
                MailMessage mail = SendMailBody.Createmessage(d);
                SmtpClient  smtp = new SmtpClient()
                {
                    Host        = ConfigurationManager.AppSettings["smtpServer"],
                    Port        = Convert.ToInt32(ConfigurationManager.AppSettings["smtpPort"]),
                    EnableSsl   = true,
                    Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["smtpUser"], ConfigurationManager.AppSettings["smtpPass"])
                };
                Console.WriteLine("Sending Email......");
                smtp.Send(mail);
                Console.WriteLine("Email Sent.");
            }
        }