private SendMailInfo ComposeMail(Comment c)
        {
            SharedBasePage requestPage = Page as SharedBasePage;

            MailMessage emailMessage = new MailMessage();

            if (requestPage.SiteConfig.NotificationEMailAddress != null &&
                requestPage.SiteConfig.NotificationEMailAddress.Length > 0)
            {
                emailMessage.To.Add(requestPage.SiteConfig.NotificationEMailAddress);
            }
            else
            {
                emailMessage.To.Add(requestPage.SiteConfig.Contact);
            }

            emailMessage.Sender = new MailAddress(requestPage.SiteConfig.Contact);

            emailMessage.Subject = String.Format("Weblog comment by '{0}' from '{1}' on '{2}'", c.Author, c.AuthorHomepage, c.TargetTitle);

            if (requestPage.SiteConfig.CommentsRequireApproval)
            {
                emailMessage.Body = String.Format("{0}\r\nComments page: {1}\r\n\r\nApprove comment: {2}\r\n\r\nDelete Comment: {3}",
                                                  HttpUtility.HtmlDecode(c.Content),
                                                  SiteUtilities.GetCommentViewUrl(c.TargetEntryId),
                                                  SiteUtilities.GetCommentApproveUrl(c.TargetEntryId, c.EntryId),
                                                  SiteUtilities.GetCommentDeleteUrl(c.TargetEntryId, c.EntryId));
            }
            else
            {
                emailMessage.Body = String.Format("{0}\r\nComments page: {1}\r\n\r\nDelete Comment: {2}",
                                                  HttpUtility.HtmlDecode(c.Content),
                                                  SiteUtilities.GetCommentViewUrl(c.TargetEntryId),
                                                  SiteUtilities.GetCommentDeleteUrl(c.TargetEntryId, c.EntryId));
                if (c.SpamState == SpamState.Spam)
                {
                    emailMessage.Body += "\r\nNot Spam: " + SiteUtilities.GetCommentApproveUrl(c.TargetEntryId, c.EntryId);
                }
            }

            if (requestPage.SiteConfig.EnableSpamBlockingService && (c.SpamState != SpamState.Spam))
            {
                emailMessage.Body += "\r\n\r\nReport as SPAM: "
                                     + SiteUtilities.GetCommentReportUrl(requestPage.SiteConfig, c.TargetEntryId, c.EntryId)
                                     + "\r\n  (Reporting SPAM will also delete the comment.)";
            }

            emailMessage.Body += "\r\n\r\n" + ApplicationResourceTable.GetSpamStateDescription(c.SpamState);

            emailMessage.IsBodyHtml   = false;
            emailMessage.BodyEncoding = System.Text.Encoding.UTF8;
            if (c.AuthorEmail != null && c.AuthorEmail.Length > 0)
            {
                emailMessage.From = new MailAddress(c.AuthorEmail);
            }
            else
            {
                emailMessage.From = new MailAddress(requestPage.SiteConfig.Contact);
            }

            emailMessage.Headers.Add("Sender", requestPage.SiteConfig.Contact);

            // add the X-Originating-IP header
            string      hostname    = Dns.GetHostName();
            IPHostEntry ipHostEntry = Dns.GetHostEntry(hostname);

            if (ipHostEntry.AddressList.Length > 0)
            {
                emailMessage.Headers.Add("X-Originating-IP", ipHostEntry.AddressList[0].ToString());
            }
            SendMailInfo sendMailInfo = new SendMailInfo(emailMessage, requestPage.SiteConfig.SmtpServer,
                                                         requestPage.SiteConfig.EnableSmtpAuthentication, requestPage.SiteConfig.UseSSLForSMTP, requestPage.SiteConfig.SmtpUserName,
                                                         requestPage.SiteConfig.SmtpPassword, requestPage.SiteConfig.SmtpPort);

            return(sendMailInfo);
        }
Beispiel #2
0
 public static string GetCommentReportUrl(SiteConfig siteConfig, string entryId, string commentId)
 {
     return(SiteUtilities.GetCommentReportUrl(siteConfig, entryId, commentId));
 }