title: Send an email where sender address is pulled from database
body: <p>I am working on a simple application where a user will authenticate and after authentication, the page will display current course information for that user.  They use a form to send selected information in an email.  What I am attempting to do is have the mail.From pull the email address from a database.  I have looked in forums and tried a few things out.  I am stuck.  What I have tried is below.     </p>
  
  <pre><code>[CAS.CasAuth]
  public class HomeController : Controller
  {
      private readonly PeopleEntities _db = new PeopleEntities();
  
      [Authentication.Authorize]
      public ActionResult Index()
      {
          var currentUser = Authentication.CurrentUser.user;
          var classes = _db.vw_People.ToList();
  
          return View(classes.Where(x =&gt; x.user == currentUser));
      }
  
      [HttpPost]
      public ActionResult Index(string[] courseid)
      {
          SendEmail(null, null, null, null, null, null);
  
          return View();
      }
  
      private bool SendEmail(string from, string to, string cc, string subject, string body)
      {
          MailMessage mail = new MailMessage();
          mail.To.Add("test@test.com");
          mail.From = new MailAddress(_db.vw_People.FirstOrDefault(f =&gt; f.Email_Addr.ToString()));
          mail.Subject = "Test Test test";
          mail.Body = "Test";
  
          SmtpClient smtp = new SmtpClient("smtp-settings", 25);
          // smtp.Host = "smtp-settings";
          //smtp.Port = 25;
          smtp.UseDefaultCredentials = false;
          smtp.Credentials = new System.Net.NetworkCredential("test", "password");
          smtp.EnableSsl = true;
          smtp.Send(mail);
  
          return true;
      }
  }
  </code></pre>
  
  <p>And this:</p>
  
  <pre><code>     var sender = _db.vw_People.FirstOrDefault(s =&gt; s.Email_Addr);
       mail.From = new MailAddress(sender);
  </code></pre>