Beispiel #1
0
        public ActionResult GenerateMachineKey(bool Audit)
        {
            System.Threading.Thread.Sleep(500);

            StringBuilder machineKey = new System.Text.StringBuilder();
            string        key64byte  = Web.Admin.Logic.Utilities.Tools.GenerateMachineKey(64);
            string        key32byte  = Web.Admin.Logic.Utilities.Tools.GenerateMachineKey(32);

            machineKey.Append("<machineKey \n");
            machineKey.Append("validationKey=\"" + key64byte + "\"\n");
            machineKey.Append("decryptionKey=\"" + key32byte + "\"\n");
            machineKey.Append("validation=\"SHA1\" decryption=\"AES\"");
            machineKey.Append("/>\n");
            String Key = machineKey.ToString();

            if (Audit)
            {
                AuditEvent.AddAppEvent(
                    new AuditEventItem
                {
                    EventType   = AuditEventType.Success,
                    IPAddress   = Request.UserHostAddress,
                    MemberEmail = Profile.Member.Email,
                    Description = "Machine Key Generated: " + Key
                }
                    );
            }

            return(Json(new
            {
                Message = "",
                Key = Key,
            }, JsonRequestBehavior.AllowGet));
        }
Beispiel #2
0
        /// <summary>
        /// Send email to a recipient and BCC members.
        /// </summary>
        /// <param name="FromName">Sender name.</param>
        /// <param name="FromEmail">Sender email.</param>
        /// <param name="ToName">Recipient name.</param>
        /// <param name="ToEmail">Recipient email.</param>
        /// <param name="Bcc">BCC recipient emails.</param>
        /// <param name="Subject">Mail subject.</param>
        /// <param name="Body">Mail body.</param>
        /// <returns>True if an email has been sent succesfully.</returns>
        public static bool SendMail(string FromName, string FromEmail, string ToName, string ToEmail, string Bcc, string Subject, string Body)
        {
            ApplicationParameters AppParams = Parameters;
            var    fromAddress  = new MailAddress(FromEmail, FromName);
            var    toAddress    = new MailAddress(ToEmail, ToName);
            string fromPassword = AppParams.MailServerSmtpPassword.Value;
            string subject      = Subject;
            string body         = Body;

            var smtp = new SmtpClient
            {
                Host           = Parameters.MailServerSmtpHost.Value,
                Port           = int.Parse(AppParams.MailServerSmtpPort.Value),
                EnableSsl      = bool.Parse(AppParams.MailServerSmtpSSLEnabled.Value),
                DeliveryMethod = SmtpDeliveryMethod.Network,
                Credentials    = new NetworkCredential(fromAddress.Address, fromPassword),
                Timeout        = 20000
            };

            using (var message = new MailMessage(fromAddress, toAddress)
            {
                Subject = subject,
                Body = body,
                IsBodyHtml = true
            })

                try
                {
                    if (Bcc != null && Bcc.Length > 0)
                    {
                        message.Bcc.Add(Bcc);
                    }
                    else
                    {
                        Bcc = "";
                    }

                    string Title = String.Format(AuditEvent.TheEmailhasBeenSent, FromName, FromEmail, ToName, ToEmail, Bcc, Subject);
                    smtp.Send(message);
                    AuditEvent.AppEventSuccess(FromEmail, Title, "##Details%%" + Title + "\r\n\r\nE-mail message:\r\n" + Body + "%%");
                    return(true);
                }
                catch (Exception ex)
                {
                    AuditEvent.AddAppEvent(
                        new AuditEventItem
                    {
                        EventType   = AuditEventType.Error,
                        IPAddress   = HttpContext.Current.Request.UserHostAddress,
                        MemberEmail = AppParams.GeneralAdminEmail.Value,
                        Description = ex.Message,
                        Details     = AuditEvent.GetSessionDetails("E-mail message:\r\n" + body + "\r\nStackTrace:\r\n" + ex.StackTrace)
                    }
                        );

                    return(false);
                }
        }