Пример #1
0
        protected void buttonTestSMTP_Click(object sender, EventArgs e)
        {
            SharedBasePage requestPage = Page as SharedBasePage;
            SiteConfig siteConfig = requestPage.SiteConfig;

            if (textSmtpServer.Text != "" & textNotificationEmailAddress.Text != "")
            {
                MailMessage emailMessage = new MailMessage();

                emailMessage.To.Add(textNotificationEmailAddress.Text);
                emailMessage.Subject = String.Format("dasBlog test message");
                emailMessage.Body =
                    String.Format("This is a test message from dasBlog. If you are reading this then everything is working properly.");
                emailMessage.IsBodyHtml = false;
                emailMessage.BodyEncoding = Encoding.UTF8;
                emailMessage.From = new MailAddress(siteConfig.Contact);
                SendMailInfo sendMailInfo = new SendMailInfo(emailMessage, textSmtpServer.Text,
                                                             checkEnableSmtpAuthentication.Checked, checkUseSSLForSMTP.Checked,
                                                             textSmtpUsername.Text, textSmtpPassword.Text,
                                                             int.Parse(textSmtpPort.Text));

                try
                {
                    sendMailInfo.SendMyMessage();
                }
                catch (Exception ex)
                {
                    //RyanG: Decode the real reason the error occured by looking at the inner exceptions
                    StringBuilder exceptionMessage = new StringBuilder();
                    Exception lastException = ex;
                    while (lastException != null)
                    {
                        if (exceptionMessage.Length > 0)
                        {
                            exceptionMessage.Append("; ");
                        }
                        exceptionMessage.Append(lastException.Message);
                        lastException = lastException.InnerException;
                    }

                    ILoggingDataService logService = requestPage.LoggingService;
                    logService.AddEvent(
                        new EventDataItem(EventCodes.SmtpError, "", exceptionMessage.ToString()));

                    Response.Redirect("FormatPage.aspx?path=SiteConfig/pageerror.format.html", true);
                }
            }
        }
Пример #2
0
		private SendMailInfo ComposeMail()
		{
			

			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);
			}

            string from = HttpUtility.HtmlEncode(email.Text);

			emailMessage.Subject = String.Format
				( "Weblog Mail from '{0} ({1})' on '{2}'"
				, HttpUtility.HtmlEncode(name.Text)
                , from
				, HttpUtility.HtmlEncode(requestPage.SiteConfig.Title));

			emailMessage.Body =  HttpUtility.HtmlEncode (comment.Text);
            emailMessage.IsBodyHtml = false;
			emailMessage.BodyEncoding = System.Text.Encoding.UTF8;
			
			if (from != null && from.Length > 0 )
			{
				emailMessage.From = new MailAddress(from);
			}
			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;
		}
Пример #3
0
        public void SendEmailReport(DateTime reportDate, SiteConfig siteConfig, IBlogDataService dataService, ILoggingDataService loggingService)
        {
            MailMessage emailMessage = new MailMessage();
            if ( siteConfig.NotificationEMailAddress != null && siteConfig.NotificationEMailAddress.Length > 0 )
            {
                emailMessage.To.Add(siteConfig.NotificationEMailAddress);
            }
            else
            {
                emailMessage.To.Add(siteConfig.Contact);
            }

            emailMessage.Subject = String.Format("Weblog Daily Activity Report for '{0}'", reportDate.ToLongDateString());
            emailMessage.Body = GenerateReportEmailBody(reportDate);
            emailMessage.IsBodyHtml = true;
            emailMessage.BodyEncoding = System.Text.Encoding.UTF8;
            emailMessage.From = new MailAddress(siteConfig.Contact);

            SendMailInfo sendMailInfo = new SendMailInfo(emailMessage, siteConfig.SmtpServer,
                siteConfig.EnableSmtpAuthentication, siteConfig.UseSSLForSMTP, siteConfig.SmtpUserName, siteConfig.SmtpPassword, siteConfig.SmtpPort);

            dataService.AddTracking(null, sendMailInfo ); // use this with null tracking object, just to get the email sent
            loggingService.AddEvent( new EventDataItem( EventCodes.ReportMailerReportSent,"",""));
        }
Пример #4
0
        private void InternalSendMail(SendMailInfo info)
        {
            try
            {
                info.SendMyMessage();
            }
            catch (Exception e)
            {
                ErrorTrace.Trace(TraceLevel.Error, e);
                if (loggingService != null)
                {
                    //CDO is very touchy and it's useful to get ALL the inner exceptions to diagnose the problem.
                    string exMessage = e.ToString();

                    Exception inner = e.InnerException;
                    while (inner != null)
                    {
                        exMessage += " INNER: " + inner.ToString();
                        inner = inner.InnerException;
                    }

                    loggingService.AddEvent(new EventDataItem(EventCodes.SmtpError, exMessage.Replace("\n", "<br />"), "InternalSendMail"));
                }
            }
        }
Пример #5
0
        public void ProcessRequest( HttpContext context )
        {
            SiteConfig siteConfig = SiteConfig.GetSiteConfig();
            string entryId;
            string title;
            string excerpt;
            string url;
            string blog_name;

            if ( !siteConfig.EnableTrackbackService )
            {
                context.Response.StatusCode = 503;
                context.Response.Status = "503 Service Unavailable";
                context.Response.End();
                return;
            }                                      

			// Try blocking them once, on the off chance they sent us a referrer
			string referrer = context.Request.UrlReferrer!=null?context.Request.UrlReferrer.AbsoluteUri:"";
			if (ReferralBlackList.IsBlockedReferrer(referrer))
			{
				if (siteConfig.EnableReferralUrlBlackList404s)
				{
					context.Response.StatusCode = 404;
					context.Response.End();
					return;
				}
			}

            entryId = context.Request.QueryString["guid"];

            if ( context.Request.HttpMethod == "POST" )
            {
                title = context.Request.Form["title"];
                excerpt= context.Request.Form["excerpt"];
                url = context.Request.Form["url"];
                blog_name = context.Request.Form["blog_name"];
            }
			/* GET is no longer in the Trackback spec. Keeping
			 * this arround for testing. Just uncomment.
            else if ( context.Request.HttpMethod == "GET" )
            {
                title = context.Request.QueryString["title"];
                excerpt= context.Request.QueryString["excerpt"];
                url = context.Request.QueryString["url"];
                blog_name = context.Request.QueryString["blog_name"];
            }
			*/
            else
            {
                context.Response.Redirect(SiteUtilities.GetStartPageUrl(siteConfig));
                return;
            }

            if ( url != null && url.Length > 0 )
            {
                try
                {
					// First line of defense, try blocking again with the URL they are tracking us back with
					if (ReferralBlackList.IsBlockedReferrer(url))
					{
						if (siteConfig.EnableReferralUrlBlackList404s)
						{
							context.Response.StatusCode = 404;
							context.Response.End();
							return;
						}
					}

					ILoggingDataService logService = LoggingDataServiceFactory.GetService(SiteConfig.GetLogPathFromCurrentContext());
					IBlogDataService dataService = BlogDataServiceFactory.GetService(SiteConfig.GetContentPathFromCurrentContext(),logService );
					
					Entry entry = dataService.GetEntry( entryId );
					
					if ( entry != null )
					{
						try
						{
							string requestBody = null;
							// see if this is a spammer
							HttpWebRequest webRequest = WebRequest.Create(url) as HttpWebRequest;
							webRequest.Method="GET";
							webRequest.UserAgent = SiteUtilities.GetUserAgent();

							HttpWebResponse response = webRequest.GetResponse() as HttpWebResponse;
								
							// now we want to get the page contents of the target body
							using (StreamReader requestReader = new StreamReader(response.GetResponseStream()))
							{
								requestBody = requestReader.ReadToEnd();
							}

							response.Close();

							// the source URL in the page could be URL encoded like the ClickThroughHandler does
							string urlEncodedBaseUrl = HttpUtility.UrlEncode(SiteUtilities.GetBaseUrl());

							// check to see if the source's page contains a link to us
							if (Regex.Match(requestBody, SiteUtilities.GetBaseUrl()).Success == false &&
								Regex.Match(requestBody, urlEncodedBaseUrl).Success == false)
							{	
								logService.AddEvent(new EventDataItem(
									EventCodes.TrackbackBlocked,
									context.Request.UserHostAddress + " because it did not contain a link",
									SiteUtilities.GetPermaLinkUrl(entryId),
									url,
									entry.Title
									));

								context.Response.StatusCode = 404;
								context.Response.End();
								return;
							}
						}
						catch
						{
							// trackback url is not even alive
							logService.AddEvent(new EventDataItem(
								EventCodes.TrackbackBlocked,
								context.Request.UserHostAddress + " because the server did not return a valid response",
								SiteUtilities.GetPermaLinkUrl(entryId),
								url,
								entry.Title
								));
							
							context.Response.StatusCode = 404;
							context.Response.End();
							return;
						}

						// if we've gotten this far, the trackback is real and valid
						Tracking t = new Tracking();
						t.PermaLink = url;
						t.Referer = context.Request.UrlReferrer != null ? context.Request.UrlReferrer.ToString() : String.Empty;
						t.RefererBlogName = blog_name;
						t.RefererExcerpt = excerpt;
						t.RefererTitle = title;
						t.RefererIPAddress = context.Request.UserHostAddress;
						t.TargetEntryId = entryId;
						t.TargetTitle = entry.Title;
						t.TrackingType = TrackingType.Trackback;

						ISpamBlockingService spamBlockingService = siteConfig.SpamBlockingService;
						if (spamBlockingService != null)
						{
							bool isSpam = false;
							try 
							{
								isSpam = spamBlockingService.IsSpam(t);
							}
							catch(Exception ex)
							{
								logService.AddEvent(new EventDataItem(EventCodes.Error, String.Format("The external spam blocking service failed for trackback from {0}. Original exception: {1}", t.PermaLink, ex), SiteUtilities.GetPermaLinkUrl(entryId)));
							}
							if (isSpam)
							{
								//TODO: maybe we can add a configuration option to moderate trackbacks.
								// For now, we'll just avoid saving suspected spam
								logService.AddEvent(new EventDataItem(
									EventCodes.TrackbackBlocked,
									context.Request.UserHostAddress + " because it was considered spam by the external blocking service.",
									SiteUtilities.GetPermaLinkUrl(entryId),
									url,
									entry.Title
									));
								context.Response.StatusCode = 404;
								context.Response.End();
								return;
							}
						}

						if ( siteConfig.SendTrackbacksByEmail &&
							siteConfig.SmtpServer != null && siteConfig.SmtpServer.Length > 0 )
						{
							MailMessage emailMessage = new MailMessage();
							if ( siteConfig.NotificationEMailAddress != null && 
								siteConfig.NotificationEMailAddress.Length > 0 )
							{
								emailMessage.To.Add(siteConfig.NotificationEMailAddress);
							}
							else
							{
								emailMessage.To.Add(siteConfig.Contact);
							}
							emailMessage.Subject = String.Format("Weblog trackback by '{0}' on '{1}'", t.PermaLink, t.TargetTitle);
							emailMessage.Body = String.Format("You were tracked back from\n{0}\r\non your weblog entry '{1}'\n({2}\r\n\r\nDelete Trackback: {3})", 
							                                  t.PermaLink, 
							                                  t.TargetTitle, 
							                                  SiteUtilities.GetPermaLinkUrl(entryId),
															  SiteUtilities.GetTrackbackDeleteUrl(entryId, t.PermaLink, t.TrackingType));


                            emailMessage.IsBodyHtml = false;
							emailMessage.BodyEncoding = System.Text.Encoding.UTF8;
							emailMessage.From = new MailAddress(siteConfig.Contact);
							SendMailInfo sendMailInfo = new SendMailInfo(emailMessage, siteConfig.SmtpServer,
                                siteConfig.EnableSmtpAuthentication, siteConfig.UseSSLForSMTP, siteConfig.SmtpUserName, siteConfig.SmtpPassword, siteConfig.SmtpPort);
							dataService.AddTracking(t, sendMailInfo );
						}
						else
						{
							dataService.AddTracking( t );
						}

						logService.AddEvent(
							new EventDataItem(
							EventCodes.TrackbackReceived,
							entry.Title,
							SiteUtilities.GetPermaLinkUrl(entryId),
							url));

						// return the correct Trackback response
						// http://www.movabletype.org/docs/mttrackback.html
						context.Response.Write("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?><response><error>0</error></response>");
						return;
					}
					
                }
				catch (System.Threading.ThreadAbortException ex)
				{
					// absorb
					ErrorTrace.Trace(System.Diagnostics.TraceLevel.Error,ex);
					return;
				}
                catch( Exception exc )
                {
                    // absorb
                    ErrorTrace.Trace(System.Diagnostics.TraceLevel.Error,exc);

					// return the correct Trackback response
					// http://www.movabletype.org/docs/mttrackback.html
					context.Response.Write("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?><response><error>1</error><message>" + exc.ToString() + "</message></response>");
					return;
                }
            }
            
            if ( entryId != null && entryId.Length > 0 )
            {
                context.Response.Redirect(SiteUtilities.GetPermaLinkUrl(siteConfig,entryId));
            }
            else
            {
                context.Response.Redirect(SiteUtilities.GetStartPageUrl(siteConfig));
            }
        }
Пример #6
0
        public string ping(
            string sourceUri,
            string targetUri)
        {

            if ( !siteConfig.EnablePingbackService )
            {
                throw new ServiceDisabledException();
            }

            string returnValue="0";


			if (ReferralBlackList.IsBlockedReferrer(sourceUri))
			{
				if (siteConfig.EnableReferralUrlBlackList404s)
				{
					this.Context.Response.StatusCode = 404;
					this.Context.Response.End();
					throw new XmlRpcFaultException(404, "not found");
				}
			}


            try
            {
                string entryId=null;
                
				// OmarS: need to rewrite the URL so w can find the entryId
                Uri uriTargetUri = new Uri( SiteUtilities.MapUrl(targetUri) );
                string query = uriTargetUri.Query;
                if ( query.Length>0 && query[0]=='?')
                {
                    query = query.Substring(1);
                }
                else
                {
                    return returnValue;
                }

                string[] queryItems = query.Split('&');
                if ( queryItems == null )
                    return returnValue;

                foreach( string queryItem in queryItems )
                {
                    string[] keyvalue = queryItem.Split('=');
                    if ( keyvalue.Length==2)
                    {
                        string key=keyvalue[0];
                        string @value=keyvalue[1];

                        if ( key == "guid")
                        {
                            entryId = @value;
                            break;
                        }
                    }
                }

                if ( entryId != null )
                {
                    Entry entry = dataService.GetEntry(entryId);
                    if ( entry != null )
                    {
                        Tracking t = new Tracking();
                        t.PermaLink = sourceUri;
						t.Referer = this.Context.Request.UrlReferrer != null ? this.Context.Request.UrlReferrer.ToString() : String.Empty;
                        t.RefererBlogName = sourceUri;
                        t.RefererExcerpt = String.Empty;
                        t.RefererTitle = sourceUri;
                        t.TargetEntryId = entryId;
                        t.TargetTitle = entry.Title;
                        t.TrackingType = TrackingType.Pingback;
                        t.RefererIPAddress = this.Context.Request.UserHostAddress;

						ISpamBlockingService spamBlockingService = siteConfig.SpamBlockingService;
						if (spamBlockingService != null)
						{
							bool isSpam = false;
							try 
							{
								isSpam = spamBlockingService.IsSpam(t);
							}
							catch(Exception ex)
							{
								logDataService.AddEvent(new EventDataItem(EventCodes.Error, String.Format("The external spam blocking service failed for pingback from {0}. Original exception: {1}", sourceUri, ex), targetUri));
							}
							if (isSpam)
							{
								//TODO: May provide moderation in the future. For now we just ignore the pingback
								logDataService.AddEvent(new EventDataItem(
									EventCodes.PingbackBlocked,
									"Pingback blocked from " + sourceUri + " because it was considered spam by the external blocking service.",
									targetUri, sourceUri));
								System.Web.HttpContext.Current.Response.StatusCode = 404;
								System.Web.HttpContext.Current.Response.End();
								throw new XmlRpcFaultException(404, "not found");
							}
						}

                        if ( siteConfig.SendPingbacksByEmail &&
                             siteConfig.SmtpServer != null && siteConfig.SmtpServer.Length > 0 )
                        {
                            MailMessage emailMessage = new MailMessage();
                            if ( siteConfig.NotificationEMailAddress != null && 
                                siteConfig.NotificationEMailAddress.Length > 0 )
                            {
                                emailMessage.To.Add(siteConfig.NotificationEMailAddress);
                            }
                            else
                            {
                                emailMessage.To.Add(siteConfig.Contact);
                            }
                            emailMessage.Subject = String.Format("Weblog pingback by '{0}' on '{1}'", sourceUri, t.TargetTitle);
                            emailMessage.Body = String.Format("You were pinged back by\n{0}\r\non your weblog entry '{1}'\n({2}\r\n\r\nDelete Trackback: {3})", 
                                                              sourceUri, 
                                                              t.TargetTitle, 
                                                              SiteUtilities.GetPermaLinkUrl(entry),
                            							      SiteUtilities.GetTrackbackDeleteUrl(entryId, t.PermaLink, t.TrackingType));

                            emailMessage.IsBodyHtml = false;
                            emailMessage.BodyEncoding = System.Text.Encoding.UTF8;
                            emailMessage.From = new MailAddress(siteConfig.Contact);
                            SendMailInfo sendMailInfo = new SendMailInfo(emailMessage, siteConfig.SmtpServer,
                                siteConfig.EnableSmtpAuthentication, siteConfig.UseSSLForSMTP, siteConfig.SmtpUserName, siteConfig.SmtpPassword, siteConfig.SmtpPort);
                            dataService.AddTracking(t, sendMailInfo );
                        }
                        else
                        {
                            dataService.AddTracking(t);
                        }
                        
                        logDataService.AddEvent(
                            new EventDataItem(EventCodes.PingbackReceived,entry.Title,targetUri,sourceUri));
                        returnValue = sourceUri;
                    }
                }
            }
            catch( Exception e )
            {
                ErrorTrace.Trace(System.Diagnostics.TraceLevel.Error,e);
                return "0";
            }
            return returnValue;
        }
Пример #7
0
        private static SendMailInfo ComposeMail(Entry entry, SiteConfig siteConfig)
        {
            System.Net.Mail.MailMessage emailMessage = new System.Net.Mail.MailMessage();

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

            emailMessage.Subject = String.Format("Weblog post by '{0}' on '{1}'", entry.Author, entry.Title);
            emailMessage.Body = String.Format("{0}<p>Post page: <a href=\"{1}\">{1}</a></p>", entry.Content, SiteUtilities.GetPermaLinkUrl(siteConfig, entry));
            emailMessage.IsBodyHtml = true;
            emailMessage.BodyEncoding = Encoding.UTF8;

            User entryAuthor = SiteSecurity.GetUser(entry.Author);

            //didn't work? try again with emailAddress...
            if (entryAuthor == null)
            {
                entryAuthor = SiteSecurity.GetUserByEmail(entry.Author);
            }

            if (entryAuthor != null && entryAuthor.EmailAddress != null && entryAuthor.EmailAddress.Length > 0)
            {
                emailMessage.From = new System.Net.Mail.MailAddress(entryAuthor.EmailAddress);
            }
            else
            {
                emailMessage.From = new System.Net.Mail.MailAddress(siteConfig.Contact);
            }

            SendMailInfo sendMailInfo = new SendMailInfo(emailMessage, siteConfig.SmtpServer,
                siteConfig.EnableSmtpAuthentication, siteConfig.UseSSLForSMTP, siteConfig.SmtpUserName, siteConfig.SmtpPassword, siteConfig.SmtpPort);

            // Christoph De Baene: Put in comments, because mail is sent through IBlogDataService where the EnableSmtpAuthentication is handled there.
            // RyanG: Added support for authentication on outgoing smtp
            /*
            if (sendMailInfo.EnableSmtpAuthentication)
            {
                sendMailInfo.Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");	// enable basic authentication
                sendMailInfo.Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", sendMailInfo.SmtpUserName);	// set the username
                sendMailInfo.Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", sendMailInfo.SmtpPassword);  // set the password
            }
            */

            return sendMailInfo;
        }
Пример #8
0
        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;
        }