Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 535477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:43:16+00:00 2026-05-13T09:43:16+00:00

Although this is a fairly common problem, I am struggling with what the best

  • 0

Although this is a fairly common problem, I am struggling with what the best way to approach it (if it needs approached at all in this case).

I have inherited a website (ASP.NET, C#) part of which contains a class full of static methods (it’s a very large class, honestly). One method in particular is for sending e-mails. It has every possible parameter I can think of and it works well enough. However, the internals of that particular method are rather cumbersome to manage and understand due to the fact that everything is shoved inside – particularly when most of the parameters aren’t used. In addition, it is somewhat difficult to handle errors, again, due to all the parameters for this one method.

Would it make more sense to actually have an EMail class which is instantiated when you want to send an e-mail? This just “feels” more right to me, though I can’t full explain why. What are your thoughts on the way to go in this particular case? How about in general?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:43:16+00:00Added an answer on May 13, 2026 at 9:43 am

    What you’re describing sounds like an example of the aphorism, “You can write FORTRAN in any language.”

    A massive class full of static methods is often (not always) a sign that somebody just didn’t “get” OOP, was stuck in a procedural-programming mindset and was trying to twist the language to do what he wanted.

    As a rule of thumb: If any method, static or instance, takes more than about 5 parameters, it’s often a sign that the method is trying to do too many things at once, and is a good candidate for refactoring into one or more classes.

    Also, if the static methods are not really related, then they should at least be split up into classes that implement related functionality.

    I’m actually wondering why you’d have a “send e-mail” method at all, given that the System.Net.Mail namespace handles just about every case, and is configurable via the app.config/web.config file, so you don’t need to pass it a server name or port. Is this perchance a “notification” method – something that individual pages are supposed to call out to in order to send one of several “standard” messages based on templates with various values filled in, and certain headers/footers automatically added? If so, there are a number of designs for this type of interaction that are much easier to work with than what you seem to have inherited. (i.e. MailDefinition)

    Update: Now having seen your comment that this is being used for exception handling, I think that the most appropriate solution is an actual exception handler. There are a ton of resources on this. For ASP.NET WebForms, I actually took the one Jeff Atwood wrote years ago, ported it to C# and made a few changes (like ignoring 404 errors). There are a number of good links in this previous question.

    My preference these days is just to treat exception handling (and subsequent e-mailing of exception reports) as a subset of logging. log4net has an SmtpAppender that’s quite capable, and you can configure it to only be used for “fatal” errors (i.e. unhandled exceptions – in your handler, you just make a LogFatal call).

    The important thing, which you’ll no doubt pick up from the SO link above and any referenced links, is that there are actually two anti-patterns here – the “miscellaneous” static class, and catching exceptions that you don’t know how to handle. This is a poor practice in .NET – in most cases you should only catch application-specific exceptions that you can recover from, and let all other exceptions bubble up, installing a global exception handler if necessary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the SQL2008 version of SMO and although it uses this class internally
Although I have my php validation doing this, thought I may as well pop
I have this linq query that works well (although it may be written better,
I'm fairly new in the Ruby + Rails scene. Although I have a very
I've written a fairly simple script that will take elements (in this case, <p>
I have a problem formulating a MySQL query to do the following task, although
Although I think this is a fairly trivial question, I could not find any
We have an app with a long polling scheme over HTTP (although this question
I'm fairly new to JFlex and JSyntaxPane although I have managed to hack together
The problem is fairly odd to me although I'm a newbie. What's going on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.