public ActionResult CheckSubscribe(string key)
 {
     using (var db = new SmtpDbContext())
     {
         var current = db.Subscribers.FirstOrDefault(s => s.Key == key && !s.IsActive);
         if (current == null)
         {
             ViewBag.ErrorMessage = "Gozleyen ticket yoxdur!";
             return(View("Index"));
         }
         current.IsActive = true;
         db.SaveChanges();
     }
     return(View());
 }
Ejemplo n.º 2
0
        public ActionResult Subscribe(string email)
        {
            if (Regex.IsMatch(email, @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$"))
            {
                using (var db = new SmtpDbContext())
                {
                    if (db.Subscribers.Any(s => s.Email == email))
                    {
                        ViewBag.ErrorMessage = "Artiq qeydiyyatdan kecmishsiniz";
                        return(View("Index"));
                    }

                    string key = Guid.NewGuid().ToString().Replace("-", "");


                    string replyLink = string.Concat(ConfigurationManager.AppSettings.Get("siteDomainName"),
                                                     "/Mail/CheckSubscribe?key=", key);

                    //ConfigurationManager.AppSettings.Get("siteDomainName");
                    //Mail/CheckSubscribe
                    //?key=

                    StringBuilder builder = new StringBuilder();
                    builder.AppendLine($"<h1>Hello,{email}!{Environment.NewLine}<h1/>");
                    builder.AppendLine($"Please check this link!{Environment.NewLine}<a href='{replyLink}'>{replyLink}</a>");

                    if (email.SendMail("New Subscriber", builder.ToString()))
                    {
                        db.Subscribers.Add(new Models.Entity.Subscriber
                        {
                            Email      = email,
                            Key        = key,
                            CreateDate = DateTime.Now
                        });
                    }

                    builder.Clear();
                }
            }
            else
            {
                ViewBag.ErrorMessage = "Email Duz deyil";
            }
            return(View("Index"));
        }
Ejemplo n.º 3
0
        public static void SendEmailAsync(string Subject, string Body, ArrayList AttachmentFiles, string CC, string BCC, bool IsHtmlFormat, string ToAddress)
        {
            SmtpDbContext  _smtpDbContext = new SmtpDbContext();
            SmtpReturnInfo smtpInfo       = _smtpDbContext.GetSmtpSync();

            string To                 = string.IsNullOrEmpty(ToAddress) ? smtpInfo.ToAddress : ToAddress;
            string From               = smtpInfo.FromAddress;
            string SMTPServer         = smtpInfo.HostName;
            int    ServerPort         = smtpInfo.PortNo;
            bool   SMTPAuthentication = smtpInfo.UseAuthentication;
            bool   SMTPEnableSSL      = smtpInfo.EnableSSL;
            string SMTPPassword       = smtpInfo.Password;
            string SMTPUsername       = smtpInfo.FromAddress;

            try
            {
                MailMessage myMessage = new MailMessage();
                myMessage.To.Add(To);
                myMessage.From       = new MailAddress(SMTPUsername);
                myMessage.Subject    = Subject;
                myMessage.Body       = Body;
                myMessage.IsBodyHtml = true;

                if (CC.Length != 0)
                {
                    myMessage.CC.Add(CC);
                }

                if (BCC.Length != 0)
                {
                    myMessage.Bcc.Add(BCC);
                }

                if (AttachmentFiles != null)
                {
                    foreach (string x in AttachmentFiles)
                    {
                        if (File.Exists(x))
                        {
                            myMessage.Attachments.Add(new Attachment(x));
                        }
                    }
                }
                SmtpClient smtp = new SmtpClient();
                if (SMTPAuthentication)
                {
                    if (SMTPUsername.Length > 0 && SMTPPassword.Length > 0)
                    {
                        smtp.Credentials = new System.Net.NetworkCredential(SMTPUsername, SMTPPassword);
                    }
                }
                smtp.EnableSsl = SMTPEnableSSL;

                smtp.Host = SMTPServer;
                smtp.Port = ServerPort;
                smtp.SendMailAsync(myMessage);
            }

            catch (Exception ex)
            {
                throw ex;
            }
        }