Esempio n. 1
0
 public List <Mail> List()
 {
     try
     {
         var mailRepository = new MailRepository();
         return(mailRepository.List());
     }
     catch (Exception e)
     {
         logger.Error(string.Format("Hata=>{0} StackTrace=>{1}", e.Message, e.StackTrace));
     }
     return(new List <Mail>());
 }
Esempio n. 2
0
        public bool SendMail(Notification notification)
        {
            var mailRepository        = new MailRepository();
            var mailRequestRepository = new MailRequestRepository();

            notification.Ip = GetIp();
            if (mailRequestRepository.List(notification.Ip).Count > 0)
            {
                throw new Exception(string.Format("Bugun daha önce mail gönderilmiştir İp=>{0}, Email =>{1}", notification.Ip, notification.Email));
            }
            var mailInfo = mailRepository.List();
            var ePosta   = new MailMessage()
            {
                From    = new MailAddress(mailInfo[0].Email),
                Subject = "İletişim",
            };
            var sb = new StringBuilder();

            sb.AppendLine("İsim:" + notification.NameSurname);
            sb.AppendLine("Mail:" + notification.Email);
            sb.AppendLine("Telefon:" + notification.PhoneNumber);
            sb.AppendLine("Açıklama:" + notification.Message);
            ePosta.Body = sb.ToString();

            ePosta.To.Add(mailInfo[0].Email);

            var smtp = new SmtpClient();

            smtp.Credentials = new System.Net.NetworkCredential(mailInfo[0].Email, mailInfo[0].Password);
            smtp.Port        = mailInfo[0].Port;
            smtp.Host        = mailInfo[0].Host;
            smtp.EnableSsl   = true;
            try
            {
                smtp.Send(ePosta);
                notification.Message = sb.ToString();
                new MailRequestRepository().Insert(notification);
            }
            catch (SmtpException e)
            {
                logger.Error(string.Format("Hata=>{0} StackTrace=>{1}", e.Message, e.StackTrace));
            }
            return(true);
        }