| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 | using System;using System.Collections.Generic;using System.Linq;using System.Net;using System.Net.Mail;using System.Web;namespace iBemsDataService.Controllers.Fms.WorkManagement.ScheduledTask{    public class AlarmConfigEmail    {        //private MailAddress sendAddress = new MailAddress("icontrolslaboratory@gmail.com");        private MailAddress toAddress = null;        private MailAddress sendAddress = null;        //private string sendPassword = "icontrols123.,";        private string sendPassword = null;        public void SetToAddress(string toMail)        {            this.toAddress = new MailAddress(toMail);        }        // Email 정보 가져오기 2019.04.        public void SetEmailInfo(string fromAdress, string fromPassword)        {            this.sendAddress = new MailAddress(fromAdress);            this.sendPassword = fromPassword;        }        // Email 정보 가져오기 2019.04.        public string SendEmail(String subject, string body)        {            SmtpClient smtp = null;            MailMessage message = null;            try            {                smtp = new SmtpClient                {                    Host = "smtp.gmail.com",                    EnableSsl = true,                    DeliveryMethod = SmtpDeliveryMethod.Network,                    Credentials = new NetworkCredential(sendAddress.Address, sendPassword),                    Timeout = 20000                };                message = new MailMessage(sendAddress, toAddress)                {                    Subject = subject,                    Body = body                };                smtp.Send(message);                return "OK";            }            catch            {                return "FAIL";            }            finally            {                if (smtp != null) { smtp.Dispose(); }                if (message != null) { message.Dispose(); }            }        }    }}
 |