title: Azure Function SendGrid
body: <p>Hi I'm basically executing a query which returns x amount of emails  that exist on a specific day and I want to send an email to all of these emails using sendgrid's api here is my code - I am running into alot of errors listed below could anyone shed some light?</p>
  
  <p>[code]</p>
  
  <pre><code>**#r "System.Data"
  #r "SendGrid"
  
  using System;
  using System.Data;
  using SendGrid.Helpers.Mail;
  
  using System.Data.SqlClient;
  using System.Text.RegularExpressions;
  using Microsoft.SqlServer.Server;
  using SendGrid;
  
          private SqlConnection conn = null;
          private SqlDataAdapter da = null;
          private SqlCommandBuilder cb = null;
          private DataSet ds = null;
          private String location = null;
  
  public void Run(TimerInfo myTimer, TraceWriter log)
      {
          log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
          string connStr = "Data Source=sdc-hwsb.database.windows.net;Initial Catalog=SDC-HotelWSBooking;Integrated Security=False;User ID=sdchwsb;Password=Trivago17!;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
          SqlConnection conn = new SqlConnection(connStr);
          conn.Open();
          string query = "SELECT email FROM dbo.test_bookings2 WHERE startDate = @startDate";
          SqlCommand cmd = new SqlCommand(query, conn);
          cmd.Parameters.AddWithValue("@startDate", DateTime.Today.ToShortDateString());
          int k = 0;
          int f = Convert.ToInt32(cmd.ExecuteNonQuery());
          while (f &gt; 0 &amp; k &lt; f)
          {
              conn = new SqlConnection(connStr);
              da = new SqlDataAdapter(query, conn);
              cb = new SqlCommandBuilder(da);
              ds = new DataSet();
              da.Fill(ds);
              String Email = Convert.ToString(ds.Tables[0].Rows[k]);
              Run1(Email,message);
              k++;
  
          }
  
      }
  
  
      public static void Run1(string email, out Mail message)
  {
        message = new Mail
          {        
          Subject = "Azure news"          
      };
  var personalization = new Personalization();
  // change to email of recipient
  personalization.AddTo(new Email(email));   
  
  Content content = new Content
  {
      Type = "text/plain",
      Value = "DD"
  };
  message.AddContent(content);
  message.AddPersonalization(personalization);
  </code></pre>
  
  <p>}</p>
  
  <pre><code>**
  </code></pre>
  
  <p>I Am getting errors reffering to the Message object sendgrid is using such as:</p>
  
  <pre><code>    2017-09-25T18:50:37.754 Function started (Id=067b32b9-7bc3-47ca-9f32-b8b92c3b57e9)
  2017-09-25T18:50:37.770 Function compilation error
  2017-09-25T18:50:37.770 run.csx(38,28): error CS0103: The name 'message' does not exist in the current context
  2017-09-25T18:50:37.807 Exception while executing function: Functions.TimerTriggerCSharp1. Microsoft.Azure.WebJobs.Script: Script compilation failed.
  2017-09-25T18:50:37.948 Function completed (Failure, Id=067b32b9-7bc3-47ca-9f32-b8b92c3b57e9, Duration=196ms)
  </code></pre>