예제 #1
0
        void btnSendPreview_Click(object sender, EventArgs e)
        {
            string baseUrl = WebUtils.GetHostRoot();

            if (WebConfigSettings.UseFoldersInsteadOfHostnamesForMultipleSites)
            {
                // in folder based sites the relative urls in the editor will already have the folder name
                // so we want to use just the raw site root not the navigation root
                baseUrl = WebUtils.GetSiteRoot();
            }

            string content = SiteUtils.ChangeRelativeUrlsToFullyQualifiedUrls(baseUrl, ImageSiteRoot, edContent.Text);

            // TODO: validate email
            Email.Send(
                GetSmtpSettings(),
                siteSettings.DefaultEmailFromAddress,
                siteSettings.DefaultFromEmailAlias,
                string.Empty,
                txtPreviewAddress.Text,
                string.Empty,
                string.Empty,
                txtSubject.Text,
                content,
                true,
                "Normal");

            //WebUtils.SetupRedirect(this, Request.RawUrl);
        }
예제 #2
0
        private void SaveLetter()
        {
            if (letter == null)
            {
                return;
            }
            if (currentUser == null)
            {
                return;
            }
            // no edits after sending
            if (letter.SendCompleteUtc > DateTime.MinValue)
            {
                // already sent, can't edit it but can save as new draft
                SaveAsNewDraft(letter);
                return;
            }

            letter.HtmlBody  = SiteUtils.ChangeRelativeUrlsToFullyQualifiedUrls(SiteRoot, imageSiteRoot, edContent.Text);
            letter.TextBody  = txtPlainText.Text;
            letter.Subject   = txtSubject.Text;
            letter.LastModBy = currentUser.UserGuid;
            if (letter.LetterGuid == Guid.Empty)
            {
                // new letter
                letter.LetterInfoGuid = letterInfoGuid;
                letter.CreatedBy      = currentUser.UserGuid;
            }

            letter.Save();
            letterGuid = letter.LetterGuid;
        }
예제 #3
0
        void btnSendPreview_Click(object sender, EventArgs e)
        {
            Page.Validate("preview");
            if (!Page.IsValid)
            {
                return;
            }

            string baseUrl = WebUtils.GetHostRoot();

            if (WebConfigSettings.UseFolderBasedMultiTenants)
            {
                // in folder based sites the relative urls in the editor will already have the folder name
                // so we want to use just the raw site root not the navigation root
                baseUrl = WebUtils.GetSiteRoot();
            }

            string content = SiteUtils.ChangeRelativeUrlsToFullyQualifiedUrls(baseUrl, ImageSiteRoot, edContent.Text);

            //log.Info(content);

            Email.SendEmail(
                SiteUtils.GetSmtpSettings(),
                siteSettings.DefaultEmailFromAddress,
                txtPreviewAddress.Text,
                string.Empty,
                string.Empty,
                txtTitle.Text,
                content,
                true,
                "Normal");
        }
예제 #4
0
        private void SaveAsNewDraft(Letter prevEdition)
        {
            letter = new Letter();

            letter.HtmlBody  = SiteUtils.ChangeRelativeUrlsToFullyQualifiedUrls(SiteRoot, imageSiteRoot, edContent.Text);
            letter.TextBody  = txtPlainText.Text;
            letter.Subject   = txtSubject.Text;
            letter.LastModBy = currentUser.UserGuid;
            if (letter.LetterGuid == Guid.Empty)
            {
                // new letter
                letter.LetterInfoGuid = letterInfoGuid;
                letter.CreatedBy      = currentUser.UserGuid;
            }

            letter.Save();
            letterGuid = letter.LetterGuid;
        }
예제 #5
0
        void btnSendToList_Click(object sender, EventArgs e)
        {
            SaveLetter();

            if (!LetterIsValidForSending())
            {
                return;
            }

            if (letter.SendCompleteUtc > DateTime.MinValue)
            {
                return;
            }

            // TODO: implement approval process
            letter.ApprovedBy = currentUser.UserGuid;
            letter.IsApproved = true;

            string baseUrl = WebUtils.GetHostRoot();

            if (WebConfigSettings.UseFoldersInsteadOfHostnamesForMultipleSites)
            {
                // in folder based sites the relative urls in the editor will already have the folder name
                // so we want to use just the raw site root not the navigation root
                baseUrl = WebUtils.GetSiteRoot();
            }

            string content = SiteUtils.ChangeRelativeUrlsToFullyQualifiedUrls(baseUrl, WebUtils.GetSiteRoot(), letter.HtmlBody);

            letter.HtmlBody = content;

            SaveLetter();

            letter.TrackSendClicked();
            SmtpSettings smtpSettings = GetSmtpSettings();

            LetterSendTask letterSender = new LetterSendTask
            {
                SiteGuid              = siteSettings.SiteGuid,
                QueuedBy              = currentUser.UserGuid,
                LetterGuid            = letter.LetterGuid,
                UnsubscribeLinkText   = Resource.NewsletterUnsubscribeLink,
                ViewAsWebPageText     = Resource.NewsletterViewAsWebPageLink,
                UnsubscribeUrl        = SiteRoot + "/eletter/Unsubscribe.aspx",
                NotificationFromEmail = siteSettings.DefaultEmailFromAddress,
                NotifyOnCompletion    = true,
                NotificationToEmail   = currentUser.Email,
                User     = smtpSettings.User,
                Password = smtpSettings.Password,
                Server   = smtpSettings.Server,
                Port     = smtpSettings.Port,
                RequiresAuthentication = smtpSettings.RequiresAuthentication,
                UseSsl              = smtpSettings.UseSsl,
                PreferredEncoding   = smtpSettings.PreferredEncoding,
                TaskUpdateFrequency = 65,
                MaxToSendPerMinute  = WebConfigSettings.NewsletterMaxToSendPerMinute
            };

            if (letterInfo.AllowArchiveView)
            {
                letterSender.WebPageUrl = SiteRoot + "/eletter/LetterView.aspx?l=" + letter.LetterInfoGuid.ToString() + "&letter=" + letter.LetterGuid.ToString();
            }

            letterSender.QueueTask();

            string redirectUrl = SiteRoot + "/eletter/SendProgress.aspx?l=" + letterInfoGuid.ToString()
                                 + "&letter=" + letterGuid.ToString()
                                 + "&t=" + letterSender.TaskGuid.ToString();

            WebTaskManager.StartOrResumeTasks();

            WebUtils.SetupRedirect(this, redirectUrl);
        }
예제 #6
0
        private void RenderRss()
        {
            Argotic.Syndication.RssFeed feed = new Argotic.Syndication.RssFeed();
            RssChannel channel = new RssChannel();

            channel.Generator = "mojoPortal Blog Module";

            channel.Language = SiteUtils.GetDefaultCulture();
            feed.Channel     = channel;
            if (module.ModuleTitle.Length > 0)
            {
                channel.Title = module.ModuleTitle;
            }
            else
            {
                channel.Title = "Blog"; // it will cause an error if this is left blank so we must populate it if the module title is an emty string.
            }

            // this became broken when we combined query string params, since pageid is not one of the params this always returns the home page url
            // instead of the blog page url
            //string pu = WebUtils.ResolveServerUrl(SiteUtils.GetCurrentPageUrl());

            string pu = WebUtils.ResolveServerUrl(SiteUtils.GetPageUrl(pageSettings));


            channel.Link     = new System.Uri(pu);
            channel.SelfLink = Request.Url;


            if (config.ChannelDescription.Length > 0)
            {
                channel.Description = config.ChannelDescription;
            }
            if (config.Copyright.Length > 0)
            {
                channel.Copyright = config.Copyright;
            }

            channel.ManagingEditor = config.ManagingEditorEmail;
            if (config.ManagingEditorName.Length > 0)
            {
                channel.ManagingEditor += " (" + config.ManagingEditorName + ")";
            }


            if (config.FeedTimeToLive > -1)
            {
                channel.TimeToLive = config.FeedTimeToLive;
            }


            //  Create and add iTunes information to feed channel
            ITunesSyndicationExtension channelExtension = new ITunesSyndicationExtension();

            channelExtension.Context.Subtitle = config.ChannelDescription;


            if (config.HasExplicitContent)
            {
                channelExtension.Context.ExplicitMaterial = ITunesExplicitMaterial.Yes;
            }
            else
            {
                channelExtension.Context.ExplicitMaterial = ITunesExplicitMaterial.No;
            }

            channelExtension.Context.Author = config.ManagingEditorEmail;
            if (config.ManagingEditorName.Length > 0)
            {
                channelExtension.Context.Author += " (" + config.ManagingEditorName + ")";
            }
            channelExtension.Context.Summary = config.ChannelDescription;
            channelExtension.Context.Owner   = new ITunesOwner(config.ManagingEditorEmail, config.ManagingEditorName);



            if (config.FeedLogoUrl.Length > 0)
            {
                try
                {
                    channelExtension.Context.Image = new Uri(config.FeedLogoUrl);
                }
                catch (ArgumentNullException) { }
                catch (UriFormatException) { }
            }


            if (config.FeedMainCategory.Length > 0)
            {
                ITunesCategory mainCat = new ITunesCategory(config.FeedMainCategory);

                if (config.FeedSubCategory.Length > 0)
                {
                    mainCat.Categories.Add(new ITunesCategory(config.FeedSubCategory));
                }


                channelExtension.Context.Categories.Add(mainCat);
            }


            feed.Channel.AddExtension(channelExtension);


            DataSet dsBlogPosts = GetData();

            DataTable posts = dsBlogPosts.Tables["Posts"];


            foreach (DataRow dr in posts.Rows)
            {
                bool inFeed = Convert.ToBoolean(dr["IncludeInFeed"]);
                if (!inFeed)
                {
                    continue;
                }

                RssItem item = new RssItem();

                int    itemId      = Convert.ToInt32(dr["ItemID"]);
                string blogItemUrl = FormatBlogUrl(dr["ItemUrl"].ToString(), itemId);
                item.Link            = new Uri(Request.Url, blogItemUrl);
                item.Guid            = new RssGuid(blogItemUrl);
                item.Title           = dr["Heading"].ToString();
                item.PublicationDate = Convert.ToDateTime(dr["StartDate"]);

                bool showAuthor = Convert.ToBoolean(dr["ShowAuthorName"]);
                if (showAuthor)
                {
                    // techically this is supposed to be an email address
                    // but wouldn't that lead to a lot of spam?

                    string authorEmail = dr["Email"].ToString();
                    string authorName  = dr["Name"].ToString();

                    if (BlogConfiguration.IncludeAuthorEmailInFeed)
                    {
                        item.Author = authorEmail + " (" + authorName + ")";
                    }
                    else
                    {
                        item.Author = authorName;
                    }
                }
                else if (config.ManagingEditorEmail.Length > 0)
                {
                    item.Author = config.ManagingEditorEmail;
                }

                item.Comments = new Uri(blogItemUrl);

                string signature = string.Empty;

                if (config.AddSignature)
                {
                    signature = "<br /><a href='" + blogItemUrl + "'>" + dr["Name"].ToString() + "</a>";
                }

                if ((config.AddCommentsLinkToFeed) && (config.AllowComments))
                {
                    signature += "&nbsp;&nbsp;" + "<a href='" + blogItemUrl + "'>...</a>";
                }

                if (config.AddTweetThisToFeed)
                {
                    signature += GenerateTweetThisLink(item.Title, blogItemUrl);
                }

                if (config.AddFacebookLikeToFeed)
                {
                    signature += GenerateFacebookLikeButton(blogItemUrl);
                }


                string blogPost = SiteUtils.ChangeRelativeUrlsToFullyQualifiedUrls(navigationSiteRoot, imageSiteRoot, dr["Description"].ToString().RemoveCDataTags());

                string staticMapLink = BuildStaticMapMarkup(dr);

                if (staticMapLink.Length > 0)
                {
                    // add a google static map
                    blogPost += staticMapLink;
                }


                if ((!config.UseExcerptInFeed) || (blogPost.Length <= config.ExcerptLength))
                {
                    item.Description = blogPost + signature;
                }
                else
                {
                    string excerpt = SiteUtils.ChangeRelativeUrlsToFullyQualifiedUrls(navigationSiteRoot, imageSiteRoot, dr["Abstract"].ToString().RemoveCDataTags());

                    if ((excerpt.Length > 0) && (excerpt != "<p>&#160;</p>"))
                    {
                        excerpt = excerpt
                                  + config.ExcerptSuffix
                                  + " <a href='"
                                  + blogItemUrl + "'>" + config.MoreLinkText + "</a><div class='excerptspacer'>&nbsp;</div>";
                    }
                    else
                    {
                        excerpt = UIHelper.CreateExcerpt(dr["Description"].ToString(), config.ExcerptLength, config.ExcerptSuffix)
                                  + " <a href='"
                                  + blogItemUrl + "'>" + config.MoreLinkText + "</a><div class='excerptspacer'>&nbsp;</div>";;
                    }

                    item.Description = excerpt;
                }



                // how to add media enclosures for podcasting
                //http://www.podcast411.com/howto_1.html

                //http://argotic.codeplex.com/wikipage?title=Generating%20an%20extended%20RSS%20feed

                //http://techwhimsy.com/stream-mp3s-with-google-mp3-player


                //Uri url = new Uri("http://media.libsyn.com/media/podcast411/411_060325.mp3");
                //string type = "audio/mpeg";
                //long length = 11779397;

                string blogGuid    = dr["BlogGuid"].ToString();
                string whereClause = string.Format("ItemGuid = '{0}'", blogGuid);


                if (!config.UseExcerptInFeed)
                {
                    DataView dv = new DataView(dsBlogPosts.Tables["Attachments"], whereClause, "", DataViewRowState.CurrentRows);

                    foreach (DataRowView rowView in dv)
                    {
                        DataRow row = rowView.Row;

                        Uri    mediaUrl      = new Uri(WebUtils.ResolveServerUrl(attachmentBaseUrl + row["ServerFileName"].ToString()));
                        long   contentLength = Convert.ToInt64(row["ContentLength"]);
                        string contentType   = row["ContentType"].ToString();

                        RssEnclosure enclosure = new RssEnclosure(contentLength, contentType, mediaUrl);
                        item.Enclosures.Add(enclosure);

                        //http://argotic.codeplex.com/wikipage?title=Generating%20an%20extended%20RSS%20feed

                        ITunesSyndicationExtension itemExtension = new ITunesSyndicationExtension();
                        itemExtension.Context.Author   = dr["Name"].ToString();
                        itemExtension.Context.Subtitle = dr["SubTitle"].ToString();
                        //itemExtension.Context.Summary = "The iTunes syndication extension properties that are used vary based on whether extending the channel or an item";
                        //itemExtension.Context.Duration = new TimeSpan(1, 2, 13);
                        //itemExtension.Context.Keywords.Add("Podcast");
                        //itemExtension.Context.Keywords.Add("iTunes");


                        whereClause = string.Format("ItemID = '{0}'", itemId);
                        DataView dvCat = new DataView(dsBlogPosts.Tables["Categories"], whereClause, "", DataViewRowState.CurrentRows);

                        foreach (DataRowView rView in dvCat)
                        {
                            DataRow r = rView.Row;

                            item.Categories.Add(new RssCategory(r["Category"].ToString()));

                            itemExtension.Context.Keywords.Add(r["Category"].ToString());
                        }

                        item.AddExtension(itemExtension);
                    }
                }



                channel.AddItem(item);
            }


            if ((config.FeedburnerFeedUrl.Length > 0) || (Request.Url.AbsolutePath.Contains("localhost")))
            {
                Response.Cache.SetExpires(DateTime.Now.AddMinutes(-30));
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                Response.Cache.VaryByParams["r"] = true;
            }
            else
            {
                Response.Cache.SetExpires(DateTime.Now.AddMinutes(30));
                Response.Cache.SetCacheability(HttpCacheability.Public);
            }


            Response.ContentType = "application/xml";

            Encoding encoding = new UTF8Encoding();

            Response.ContentEncoding = encoding;

            using (XmlTextWriter xmlTextWriter = new XmlTextWriter(Response.OutputStream, encoding))
            {
                xmlTextWriter.Formatting = Formatting.Indented;

                //////////////////
                // style for RSS Feed viewed in browsers
                if (ConfigurationManager.AppSettings["RSSCSS"] != null)
                {
                    string rssCss = ConfigurationManager.AppSettings["RSSCSS"].ToString();
                    xmlTextWriter.WriteWhitespace(" ");
                    xmlTextWriter.WriteRaw("<?xml-stylesheet type=\"text/css\" href=\"" + cssBaseUrl + rssCss + "\" ?>");
                }

                if (ConfigurationManager.AppSettings["RSSXsl"] != null)
                {
                    string rssXsl = ConfigurationManager.AppSettings["RSSXsl"].ToString();
                    xmlTextWriter.WriteWhitespace(" ");
                    xmlTextWriter.WriteRaw("<?xml-stylesheet type=\"text/xsl\" href=\"" + cssBaseUrl + rssXsl + "\" ?>");
                }
                ///////////////////////////

                feed.Save(xmlTextWriter);
            }
        }
예제 #7
0
        private void RenderRss()
        {
            if (pageSettings == null)
            {
                return;
            }

            RssForum rssForum = new RssForum();

            rssForum.SiteId      = siteSettings.SiteId;
            rssForum.ModuleId    = moduleId;
            rssForum.PageId      = pageId;
            rssForum.ItemId      = itemId;
            rssForum.ThreadId    = threadId;
            rssForum.MaximumDays = maxDaysOld;

            Argotic.Syndication.RssFeed feed = new Argotic.Syndication.RssFeed();
            RssChannel channel = new RssChannel();

            channel.Generator = "mojoPortal Forum module";

            string channelLink = WebUtils.ResolveServerUrl(SiteUtils.GetPageUrl(pageSettings));

            channel.Link = new System.Uri(channelLink);

            // if (config.ChannelDescription.Length > 0) { channel.Description = config.ChannelDescription; }

            feed.Channel = channel;

            string target = navigationSiteRoot + "/Forums/Thread.aspx?pageid=";

            using (IDataReader posts = rssForum.GetPostsForRss())
            {
                while ((posts.Read()) && (entryCount <= entriesLimit))
                {
                    string pageViewRoles   = posts["AuthorizedRoles"].ToString();
                    string moduleViewRoles = posts["ViewRoles"].ToString();
                    bool   include         = (bypassPageSecurity ||
                                              (pageViewRoles.Contains("All Users")) &&
                                              ((moduleViewRoles.Length == 0) || (moduleViewRoles.Contains("All Users")))
                                              )
                    ;

                    if (!include)
                    {
                        continue;
                    }

                    RssItem item = new RssItem();

                    item.Title           = posts["Subject"].ToString();
                    item.Description     = SiteUtils.ChangeRelativeUrlsToFullyQualifiedUrls(navigationSiteRoot, imageSiteRoot, posts["Post"].ToString());
                    item.PublicationDate = Convert.ToDateTime(posts["PostDate"]);

                    int p = Convert.ToInt32(posts["PageID"]);
                    int t = Convert.ToInt32(posts["ThreadID"]);

                    //if (target.IndexOf("&thread=") < 0 && target.IndexOf("?thread=") < 0)
                    //{
                    //    if (target.IndexOf("?") < 0)
                    //    {
                    //        target += "?thread=" + posts["ThreadID"].ToString() + "#post" + posts["PostID"].ToString();
                    //    }
                    //    else
                    //    {
                    //        target += "&thread=" + posts["ThreadID"].ToString() + "#post" + posts["PostID"].ToString();
                    //    }
                    //}

                    //https://www.mojoportal.com/Forums/Thread.aspx?pageid=5&t=11417~1#post47516
                    if ((isGoogleFeedReader) && (ForumConfiguration.UseOldParamsForGoogleReader))
                    {
                        //item.Link = new System.Uri(target + p.ToInvariantString() + "&thread=" + t.ToInvariantString() + "#post" + posts["PostID"].ToString());
                        item.Link = new System.Uri(target + p.ToInvariantString() + "&thread=" + t.ToInvariantString());
                    }
                    else
                    {
                        item.Link = new System.Uri(target + p.ToInvariantString() + "&t=" + t.ToInvariantString() + "~-1#post" + posts["PostID"].ToString());
                    }

                    RssGuid g = new RssGuid(target, true);
                    item.Guid = g;

                    item.Author = posts["StartedBy"].ToString();

                    channel.AddItem(item);
                    entryCount += 1;
                }
            }

            Response.Cache.SetExpires(DateTime.Now.AddMinutes(5));
            Response.Cache.SetCacheability(HttpCacheability.Public);
            Response.ContentType = "application/xml";

            Encoding encoding = new UTF8Encoding();

            Response.ContentEncoding = encoding;

            using (XmlTextWriter xmlTextWriter = new XmlTextWriter(Response.OutputStream, encoding))
            {
                xmlTextWriter.Formatting = Formatting.Indented;

                //////////////////
                // style for RSS Feed viewed in browsers
                if (ConfigurationManager.AppSettings["RSSCSS"] != null)
                {
                    string rssCss = ConfigurationManager.AppSettings["RSSCSS"].ToString();
                    xmlTextWriter.WriteWhitespace(" ");
                    xmlTextWriter.WriteRaw("<?xml-stylesheet type=\"text/css\" href=\"" + cssBaseUrl + rssCss + "\" ?>");
                }

                if (ConfigurationManager.AppSettings["RSSXsl"] != null)
                {
                    string rssXsl = ConfigurationManager.AppSettings["RSSXsl"].ToString();
                    xmlTextWriter.WriteWhitespace(" ");
                    xmlTextWriter.WriteRaw("<?xml-stylesheet type=\"text/xsl\" href=\"" + cssBaseUrl + rssXsl + "\" ?>");
                }
                ///////////////////////////


                feed.Save(xmlTextWriter);
            }
        }
예제 #8
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            bool isValid = true;

            reqEmail.Validate();

            if (!reqEmail.IsValid)
            {
                isValid = false;
            }

            regexEmail.Validate();

            if (!regexEmail.IsValid)
            {
                isValid = false;
            }

            if (isValid && !string.IsNullOrWhiteSpace(edMessage.Text))
            {
                if (siteSettings.BadWordCheckingEnabled && (config.BlockBadWords || siteSettings.BadWordCheckingEnforced))
                {
                    if (edMessage.Text.ContainsBadWords() ||
                        txtName.Text.ContainsBadWords() ||
                        txtEmail.Text.ContainsBadWords() ||
                        txtSubject.Text.ContainsBadWords())
                    {
                        lblMessage.Text    = ContactFormResources.BadWordsFound;
                        lblMessage.Visible = true;
                        return;
                    }
                }

                if (config.UseSpamBlocking && divCaptcha.Visible)
                {
                    if (!captcha.IsValid)
                    {
                        return;
                    }
                }

                string subjectPrefix = config.SubjectPrefix;

                if (subjectPrefix.Length == 0)
                {
                    subjectPrefix = Title;
                }

                StringBuilder message = new StringBuilder();
                message.Append(txtName.Text + "<br />");
                message.Append(txtEmail.Text + "<br /><br />");
                message.Append(SiteUtils.ChangeRelativeUrlsToFullyQualifiedUrls(SiteUtils.GetNavigationSiteRoot(), WebUtils.GetSiteRoot(), edMessage.Text));
                message.Append("<br /><br />");

                if (config.AppendIPToMessageSetting)
                {
                    message.Append("HTTP_USER_AGENT: " + Page.Request.ServerVariables["HTTP_USER_AGENT"] + "<br />");
                    message.Append("REMOTE_HOST: " + Page.Request.ServerVariables[WebConfigSettings.RemoteHostServerVariable] + "<br />");
                    message.Append("REMOTE_ADDR: " + SiteUtils.GetIP4Address() + "<br />");
                    message.Append("LOCAL_ADDR: " + Page.Request.ServerVariables["LOCAL_ADDR"] + "<br />");
                }

                Module m = new Module(ModuleId);
                if (config.KeepMessages && (m.ModuleGuid != Guid.Empty))
                {
                    ContactFormMessage contact = new ContactFormMessage();
                    contact.ModuleGuid           = m.ModuleGuid;
                    contact.SiteGuid             = siteSettings.SiteGuid;
                    contact.Message              = message.ToString();
                    contact.Subject              = config.SubjectPrefix + ": " + txtSubject.Text;
                    contact.UserName             = txtName.Text;
                    contact.Email                = txtEmail.Text;
                    contact.CreatedFromIpAddress = SiteUtils.GetIP4Address();

                    if (Request.IsAuthenticated)
                    {
                        SiteUser currentUser = SiteUtils.GetCurrentSiteUser();
                        if (currentUser != null)
                        {
                            contact.UserGuid = currentUser.UserGuid;
                        }
                    }

                    contact.Save();
                }

                string fromAddress = siteSettings.DefaultEmailFromAddress;

                if (config.UseInputAsFromAddress)
                {
                    fromAddress = txtEmail.Text;
                }

                if ((config.EmailAddresses != null) && (config.EmailAddresses.Count > 0))
                {
                    SmtpSettings smtpSettings = SiteUtils.GetSmtpSettings();

                    if ((pnlToAddresses.Visible) && (ddToAddresses.SelectedIndex > -1))
                    {
                        string to = config.EmailAddresses[ddToAddresses.SelectedIndex];

                        try
                        {
                            Email.SendEmail(
                                smtpSettings,
                                fromAddress,
                                txtEmail.Text,
                                to,
                                string.Empty,
                                config.EmailBccAddresses,
                                subjectPrefix + ": " + this.txtSubject.Text,
                                message.ToString(),
                                true,
                                "Normal");
                        }
                        catch (Exception ex)
                        {
                            log.Error("error sending email from address was " + fromAddress + " to address was " + to, ex);
                        }
                    }
                    else
                    {
                        foreach (string to in config.EmailAddresses)
                        {
                            try
                            {
                                Email.SendEmail(
                                    smtpSettings,
                                    fromAddress,
                                    txtEmail.Text,
                                    to,
                                    string.Empty,
                                    config.EmailBccAddresses,
                                    subjectPrefix + ": " + this.txtSubject.Text,
                                    message.ToString(),
                                    true,
                                    "Normal");
                            }
                            catch (Exception ex)
                            {
                                log.Error("error sending email from address was " + fromAddress + " to address was " + to, ex);
                            }
                        }
                    }
                }
                else
                {
                    log.Info("contact form submission received but not sending email because notification email address is not configured.");
                }

                lblMessage.Text = ContactFormResources.ContactFormThankYouLabel;
                pnlSend.Visible = false;
            }
            else
            {
                if (string.IsNullOrWhiteSpace(edMessage.Text))
                {
                    lblMessage.Text = ContactFormResources.ContactFormEmptyMessageWarning;
                }
                else
                {
                    lblMessage.Text = "invalid";
                }
            }

            btnSend.Text    = ContactFormResources.ContactFormSendButtonLabel;
            btnSend.Enabled = true;
        }
예제 #9
0
        private void btnPostComment_Click(object sender, EventArgs e)
        {
            if (!IsValidComment())
            {
                return;
            }
            if (news == null)
            {
                return;
            }

            //if (news.AllowCommentsForDays < 0)
            //{
            //    WebUtils.SetupRedirect(this, Request.RawUrl);
            //    return;
            //}

            //DateTime endDate = news.StartDate.AddDays((double)news.AllowCommentsForDays);
            //if ((endDate < DateTime.UtcNow) && (news.AllowCommentsForDays > 0)) { return; }

            string attachFile1     = null;
            string attachFile2     = null;
            string attachmentsPath = NewsHelper.AttachmentsPath(siteSettings.SiteId, news.NewsID);

            if (uplAttachFile1.UploadedFiles.Count > 0 || uplAttachFile2.UploadedFiles.Count > 0)
            {
                try
                {
                    string fileSystemPath = Server.MapPath(attachmentsPath);

                    if (!Directory.Exists(fileSystemPath))
                    {
                        Directory.CreateDirectory(fileSystemPath);
                    }
                }
                catch (Exception ex)
                {
                }
            }

            if (uplAttachFile1.UploadedFiles.Count > 0)
            {
                if (SiteUtils.IsAllowedUploadBrowseFile(uplAttachFile1.UploadedFiles[0].GetExtension(), NewsConfiguration.JobApplyAttachFileExtensions))
                {
                    attachFile1 = uplAttachFile1.UploadedFiles[0].FileName.ToCleanFileName(WebConfigSettings.ForceLowerCaseForUploadedFiles);

                    int i = 1;
                    while (File.Exists(VirtualPathUtility.Combine(attachmentsPath, attachFile1)))
                    {
                        attachFile1 = i.ToInvariantString() + attachFile1;
                        i          += 1;
                    }
                }
            }
            if (uplAttachFile2.UploadedFiles.Count > 0)
            {
                if (SiteUtils.IsAllowedUploadBrowseFile(uplAttachFile2.UploadedFiles[0].GetExtension(), NewsConfiguration.JobApplyAttachFileExtensions))
                {
                    attachFile2 = uplAttachFile2.UploadedFiles[0].FileName.ToCleanFileName(WebConfigSettings.ForceLowerCaseForUploadedFiles);

                    int i = 1;
                    while (File.Exists(VirtualPathUtility.Combine(attachmentsPath, attachFile2)))
                    {
                        attachFile2 = i.ToInvariantString() + attachFile2;
                        i          += 1;
                    }
                }
            }

            News.AddNewsComment(
                news.NewsID,
                txtFullName.Text,
                txtPosition.Text,
                url,
                txtMessage.Text,
                txtAddress.Text,
                txtEmail.Text,
                txtPhone.Text,
                attachFile1,
                attachFile2,
                DateTime.UtcNow);

            if (!string.IsNullOrEmpty(attachFile1))
            {
                string newAttachmentsPath = VirtualPathUtility.Combine(attachmentsPath, attachFile1);
                uplAttachFile1.UploadedFiles[0].SaveAs(Server.MapPath(newAttachmentsPath));
            }
            if (!string.IsNullOrEmpty(attachFile2))
            {
                string newAttachmentsPath = VirtualPathUtility.Combine(attachmentsPath, attachFile2);
                uplAttachFile2.UploadedFiles[0].SaveAs(Server.MapPath(newAttachmentsPath));
            }

            try
            {
                StringBuilder message = new StringBuilder();

                //message.Append(string.Format("<a target='_blank' href='{0}'>{1}</a>", url, url) + "<br /><br />");

                if (!string.IsNullOrEmpty(txtPosition.Text.Trim()))
                {
                    message.Append("<b>" + NewsResources.JobPositionLabel + ":</b> " + txtPosition.Text.Trim() + "<br />");
                }
                if (!string.IsNullOrEmpty(txtFullName.Text.Trim()))
                {
                    message.Append("<b>" + NewsResources.JobFullNameLabel + ":</b> " + txtFullName.Text.Trim() + "<br />");
                }
                if (!string.IsNullOrEmpty(txtAddress.Text.Trim()))
                {
                    message.Append("<b>" + NewsResources.JobAddressLabel + ":</b> " + txtAddress.Text.Trim() + "<br />");
                }
                if (!string.IsNullOrEmpty(txtEmail.Text.Trim()))
                {
                    message.Append("<b>" + NewsResources.JobEmailLabel + ":</b> " + txtEmail.Text.Trim() + "<br />");
                }
                if (!string.IsNullOrEmpty(txtPhone.Text.Trim()))
                {
                    message.Append("<b>" + NewsResources.JobPhoneLabel + ":</b> " + txtPhone.Text.Trim() + "<br />");
                }
                if (!string.IsNullOrEmpty(attachFile1))
                {
                    string attachFile = string.Format("<a target='_blank' href='{0}'>{1}</a>", basePage.SiteRoot + Page.ResolveUrl(NewsHelper.AttachmentsPath(siteSettings.SiteId, newsId)) + attachFile1, attachFile1);
                    message.Append("<b>" + NewsResources.JobAttachFile1Label + ":</b> " + attachFile + "<br />");
                }
                if (!string.IsNullOrEmpty(attachFile2))
                {
                    string attachFile = string.Format("<a target='_blank' href='{0}'>{1}</a>", basePage.SiteRoot + Page.ResolveUrl(NewsHelper.AttachmentsPath(siteSettings.SiteId, newsId)) + attachFile2, attachFile2);
                    message.Append("<b>" + NewsResources.JobAttachFile2Label + ":</b> " + attachFile + "<br />");
                }

                message.Append("<b>" + NewsResources.JobMessageLabel + ":</b><br />" + SiteUtils.ChangeRelativeUrlsToFullyQualifiedUrls(SiteUtils.GetNavigationSiteRoot(), WebUtils.GetSiteRoot(), txtMessage.Text));
                message.Append("<br /><br />");

                EmailTemplate template = EmailTemplate.Get(siteSettings.SiteId, "JobApplyNotification");

                string fromAddress = siteSettings.DefaultEmailFromAddress;
                string fromAlias   = template.FromName;
                if (fromAlias.Length == 0)
                {
                    fromAlias = siteSettings.DefaultFromEmailAlias;
                }

                NewsHelper.SendCommentNotification(
                    SiteUtils.GetSmtpSettings(),
                    siteSettings.SiteGuid,
                    fromAddress,
                    fromAlias,
                    template.ToAddresses,
                    template.ReplyToAddress,
                    template.CcAddresses,
                    template.BccAddresses,
                    template.Subject,
                    template.HtmlBody,
                    siteSettings.SiteName,
                    message.ToString());
            }
            catch (Exception ex)
            {
                log.Error("Error sending email from address was " + siteSettings.DefaultEmailFromAddress + " to address was " + siteSettings.CompanyPublicEmail, ex);
            }

            lblMessage.Text       = MessageTemplate.GetMessage("JobApplyThankYouMessage", NewsResources.JobApplyThankYouLabel);
            pnlNewComment.Visible = false;
        }