Exemplo n.º 1
0
    protected void CancelAccount_Click(object sender, EventArgs e)
    {
        MembershipUser currUser = Membership.GetUser();

        Database db    = Global.GetDbConnection();
        var      email = new EmailMessage(db.GetEmailTemplate(9));

        email.From = "*****@*****.**";         // Placeholder, will be replaced by Email Engine.
        email.ReplaceGeneralTokens();
        email.ApplyToUser(currUser, db.ORManager.Get <UserInformation>(currUser.ProviderUserKey));
        email.ToAddress = "*****@*****.**";
        email.ReplaceInMessage(TOKEN_CANCELLATION_REASON, AccountCancellationReason.Text);
        RtEngines.EmailEngine.SendEmail(email.GetMailMessage());

        currUser.IsApproved = false;
        Membership.UpdateUser(currUser);

        // TODO: Replace this with a better way of logging the user out if there is one.
        HttpCookie authCookie = Request.Cookies[".ASPXAUTH"];

        authCookie.Expires = DateTime.Now.AddYears(-1);
        Response.Cookies.Set(authCookie);

        redirectHome();
    }
Exemplo n.º 2
0
        public virtual void SendReport(int id)
        {
            ReportPartGenerator rpg         = new ReportPartGenerator(_db);
            EmailMessage        email       = new EmailMessage(_customReportTemplate);
            StringBuilder       htmlBuilder = new StringBuilder();
            Dictionary <string, MemoryStream> imageStreams = new Dictionary <string, MemoryStream>();
            int imgCounter = 0;

            CustomReport report = _db.ORManager.Get <CustomReport>(id);

            // Prepare the EmailMessage
            email.From = "*****@*****.**";                       // Placeholder - will be replaced by email engine
            email.ReplaceGeneralTokens();
            email.ApplyToUser(Membership.GetUser(report.UserId), _db.ORManager.Get <UserInformation>(report.UserId));
            email.ReplaceInMessage(TOKEN_REPORT_TITLE, report.Name);

            // Fetch the custom report components
            ICriteria componentCriteria = _db.ORManager.Session.CreateCriteria(typeof(CustomReportComponent)).Add(Expression.Eq("CustomReport.Id", id));
            IList <CustomReportComponent> components = componentCriteria.List <CustomReportComponent>();

            htmlBuilder.Append("<table class=\"ReportComponentsTable\">");

            // Add each custom report component to the custom report
            foreach (CustomReportComponent component in components)
            {
                GeneratedReportPart grp = rpg.GenerateReport(component);
                if (grp.Bytes != null)
                {
                    // Create a placeholder for the embedded image
                    string cid = string.Format("{0}{1}", CID_REPORT_IMAGE, imgCounter++);

                    // Create an embedded image tag
                    htmlBuilder.AppendFormat("<tr><td><img src=cid:{0}><br /></td></tr>", cid);

                    // Generate and save the memory stream for this embeded image
                    MemoryStream ms = new MemoryStream(grp.Bytes);
                    imageStreams.Add(cid, ms);
                }
                else
                {
                    // Append the raw HTML
                    htmlBuilder.AppendFormat("<tr><td>{0}</td></tr>", grp.Html);
                }
            }

            htmlBuilder.Append("</table>");

            // Insert report components into email message
            email.ReplaceInMessage(TOKEN_REPORT_CONTENT, htmlBuilder.ToString());
            MailMessage msg = email.GetMailMessage();

            // Create Text-Only AlternateView
            AlternateView plainView = AlternateView.CreateAlternateViewFromString("Your email client does not appear to support viewing HTML emails.  Your email client must support this in order to view this email.", Encoding.Default, "text/plain");

            msg.AlternateViews.Add(plainView);

            // Prepare new AlternateView and clear the message body
            AlternateView htmlView = AlternateView.CreateAlternateViewFromString(msg.Body, Encoding.Default, MediaTypeNames.Text.Html);

            htmlView.TransferEncoding = TransferEncoding.SevenBit;
            msg.AlternateViews.Add(htmlView);
            msg.Body = null;

            // Embed Logo
            EmbedGifImage(htmlView, GetEmbeddedImage("RankTrend-Logo.gif"), "EmbeddedLogo");

            // Embed the images
            foreach (string key in imageStreams.Keys)
            {
                EmbedPngImage(htmlView, imageStreams[key], key);
            }

            // Send the email
            RtEngines.EmailEngine.SendEmail(msg, true);
        }