title: How to send email from a Windows service?
body: <p>I need to send lots of emails (probably hundreds a day) on a schedule. The way I'm thinking to do it is as follows but the problem is that my Body field can get very big, and if I add it as a string, it gets ugly.</p>
  <pre><code>SmtpClient client = new SmtpClient(); //host and port picked from web.config
  client.EnableSsl = true;
  
  MailMessage message = new MailMessage();
  
  message.Body = &quot;test from winservice&quot;; // HERE IS MY PROBLEM
  message.IsBodyHtml = true;
  message.From = new MailAddress(&quot;donotreply@abcde.com&quot;);
  message.Subject = &quot;My subject&quot;;
  message.To.Add(new MailAddress(&quot;piniusha@abcde.com&quot;));
  try
  {
      client.Send(message);
  }
  catch (Exception)
  {
     
  }
  </code></pre>
  <p>When I had to do it from an aspx page, I used:</p>
  <pre><code>MailDefinition message = new MailDefinition();  
          
  message.BodyFileName = @&quot;~\EmailTemplate\Template1.htm&quot;;
  ListDictionary replacements = new ListDictionary();
  replacements.Add(&quot;&lt;% Name %&gt;&quot;, this.txtName.Text);
  replacements.Add(&quot;&lt;% PhoneOrEmail %&gt;&quot;, this.txtPhoneOrEmail.Text);
  replacements.Add(&quot;&lt;% Message %&gt;&quot;, this.txtMessage.Text);
  MailMessage msgHtml = message.CreateMailMessage(RECIPIENTS, replacements, new LiteralControl());
  </code></pre>
  <p>I think it is an elegant solution, but I don't want to reference to  <code>System.Web.UI.WebControls.MailDefinition </code> because I'm in Winservice.</p>
  <ol>
  <li>How can I send bulk emails from Winservice?</li>
  <li>Is it possible to send the emails from a Gmail account? Or they are going to block me after a while?</li>
  </ol>