How to configure SMTP mail setting



There are a number of things that you have to consider:

  1. Dont fetch the smpt parameters from database inside the function. Pass the parameters to the function. This will helps if you want to send many emails repeatedly and you don't have to connect to database each time.
  2. Don't suppress the exception. Log it or throw the exception so that outer module can handle it.
  3. As said earlier by c45207, store the full SMPT host address in the database.
  4. The code only sends mail to single person. Instead use IList _pToMailId and loop it as follows:

                foreach (var to in _pToMailId)
                {
                    message .To.Add(to);
                }
    

    You can repead this for CC and BCC respectively.