JRHeaven : Free Computer Books, IT Books, Project Guidelines, Novels and Many More...

Monday, June 22, 2015

Create Windows Service to send mail daily using ASP.Net and C#


This article explains, How to create Windows Service in ASP.Net with C# to send mail on daily basis. So, we explain this step by step as following :


STEP 1 : 

Create Windows Service Proejct in Microsoft Visual Studio 2012 and give project name as   "WindowsServiceProject1".

STEP 2 : 

Now update your App.Config file as follow :
<configuration>
  <appSettings>
    <add key="StartTime" value="03:50 PM "/>
    <add key="callDuration" value="2"/>
    <add key="CallType" value="1"/>
    <add key="FromMail" value="your_from_email_id@gmail.com"/>
    <add key="Password" value="your_email_id_password"/>
    <add key="Host" value="smtp.gmail.com"/>
  </appSettings>
  <system.net>
    <mailSettings>
      <smtp from="your_from_email_id@gmail.com">
        <network host="smtp.gmail.com" userName="your_from_email_id@gmail.com" password="your_email_id_password" enableSsl="true" port="587" />
      </smtp>
    </mailSettings>
  </system.net>
</configuration>
In this configuration settings, we use gmail email id to send mail, so for that we use smtp.gmail.com as host and Port number 587.