From: Jaben C. <ja...@us...> - 2007-03-20 09:01:16
|
Update of /cvsroot/yafdotnet/yafsrc/pages In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv5880/yafsrc/pages Modified Files: Tag: v1_0_2_NETv2 ForumPage.cs Log Message: Minor--cleaned up email send Index: ForumPage.cs =================================================================== RCS file: /cvsroot/yafdotnet/yafsrc/pages/Attic/ForumPage.cs,v retrieving revision 1.76.2.17 retrieving revision 1.76.2.18 diff -C2 -d -r1.76.2.17 -r1.76.2.18 *** ForumPage.cs 20 Oct 2006 09:18:05 -0000 1.76.2.17 --- ForumPage.cs 20 Mar 2007 09:01:10 -0000 1.76.2.18 *************** *** 252,278 **** if ( ( int ) m_pageinfo ["MailsPending"] > 0 ) { ! try { ! using ( DataTable dt = DB.mail_list() ) { ! for ( int i = 0; i < dt.Rows.Count; i++ ) { ! // Build a MailMessage ! if ( dt.Rows [i] ["ToUser"].ToString().Trim() != String.Empty ) { ! Utils.SendMail( this, BoardSettings.ForumEmail, ( string ) dt.Rows [i] ["ToUser"], ( string ) dt.Rows [i] ["Subject"], ( string ) dt.Rows [i] ["Body"] ); } ! DB.mail_delete( dt.Rows [i] ["MailID"] ); } if ( IsAdmin ) this.AddAdminMessage( "Sent Mail", String.Format( "Sent {0} mails.", dt.Rows.Count ) ); } } ! catch ( Exception x ) { ! DB.eventlog_create( PageUserID, this, x ); ! if ( IsAdmin ) ! { ! this.AddAdminMessage( "Error sending emails to users", x.ToString() ); ! } } } --- 252,317 ---- if ( ( int ) m_pageinfo ["MailsPending"] > 0 ) { ! SendMailThread(); ! } ! } ! ! private void SendMailThread() ! { ! try ! { ! System.Net.Mail.SmtpClient smtpSend = new System.Net.Mail.SmtpClient( BoardSettings.SmtpServer ); ! // short timeout... ! smtpSend.Timeout = 10000; ! ! if ( BoardSettings.SmtpUserName != null && BoardSettings.SmtpUserPass != null ) { ! smtpSend.Credentials = new System.Net.NetworkCredential( BoardSettings.SmtpUserName, BoardSettings.SmtpUserPass ); ! } ! ! using ( DataTable dt = DB.mail_list() ) ! { ! for ( int i = 0; i < dt.Rows.Count; i++ ) { ! // Build a MailMessage ! if ( dt.Rows [i] ["ToUser"].ToString().Trim() != String.Empty ) { ! try { ! using ( System.Net.Mail.MailMessage emailMessage = new System.Net.Mail.MailMessage() ) ! { ! emailMessage.To.Add( dt.Rows [i] ["ToUser"].ToString() ); ! emailMessage.From = new System.Net.Mail.MailAddress( BoardSettings.ForumEmail ); ! emailMessage.Subject = dt.Rows [i] ["Subject"].ToString(); ! emailMessage.Body = dt.Rows [i] ["Body"].ToString(); ! ! if ( !System.Text.RegularExpressions.Regex.IsMatch( emailMessage.Body, @"^([0-9a-z!@#\$\%\^&\*\(\)\-=_\+])", System.Text.RegularExpressions.RegexOptions.IgnoreCase ) || ! !System.Text.RegularExpressions.Regex.IsMatch( emailMessage.Subject, @"^([0-9a-z!@#\$\%\^&\*\(\)\-=_\+])", System.Text.RegularExpressions.RegexOptions.IgnoreCase ) ) ! { ! emailMessage.BodyEncoding = Encoding.UTF8; ! } ! ! smtpSend.Send( emailMessage ); ! } } ! catch ( System.FormatException ) ! { ! // we still want to continue and delete ! } ! catch ! { ! throw; ! } } + DB.mail_delete( dt.Rows [i] ["MailID"] ); if ( IsAdmin ) this.AddAdminMessage( "Sent Mail", String.Format( "Sent {0} mails.", dt.Rows.Count ) ); } } ! } ! catch ( Exception x ) ! { ! DB.eventlog_create( PageUserID, this, x ); ! if ( IsAdmin ) { ! this.AddAdminMessage( "Error sending emails to users", x.ToString() ); } } |