History: I have a scenario where I have several project(let's say 4) in solution where I have a WCF service, a Website and a shared class library. I have to send email to users on demand and also schedule the email for WCF service. As the email configuration is same, I was thinking to move them to shared library project so that I can consume the service from both web and webservice project when needed.
The problem: the problem is, when i moved the configuration to app.config of the shared project, it is not behaving as expected. I know that if i move this code to web.config it will work. :
<system.net>
<mailSettings>
<smtp from="noreply@webcruiter.com">
<network host="smtp.sendgrid.net" userName="candidatedev" defaultCredentials="false" password="foxed-kqStTg1" port="587" enableSsl="true" />
</smtp>
</mailSettings>
but I want the service to consume the configuration from class library instead of web.config.
this is my email service which is now in shared library:
public class EmailService : IEmailService
{
public void SendEmail(MailMessage message)
{
SmtpClient smtpClient = new SmtpClient();
smtpClient.Send(message);
message.Dispose();
}
}
the suggested answer for this in comment is not answering my query. I want to centralize the email setting as it is same for both project. I need ideas or suggestion about how to go around and make it work the way i want.