public ActionResult SendFromResidentToResident([Bind(Include = "Id,Resident,BuildingName,Unit,Subject,Body,RecipientsUnit")] Messages messages) { if (ModelState.IsValid) { db.Messages.Add(messages); db.SaveChanges(); string residentEmail = null; string sendersEmail = null; var residentEmailQuery = from rm in db.Residents where ((rm.Unit == messages.RecipientsUnit) && (rm.Location == messages.BuildingName)) select rm.EmailAddress; foreach (string result in residentEmailQuery) { residentEmail = result; } var sendersEmailQuery = from se in db.Residents where ((se.Unit == messages.Unit) && (se.Location == messages.BuildingName)) select se.EmailAddress; foreach (string result in sendersEmailQuery) { sendersEmail = result; } MailGun managerMessageToResident = new MailGun(); managerMessageToResident.SendFromResidentToResident(residentEmail, messages.Subject, messages.Body, messages.Resident, messages.BuildingName, messages.Unit, sendersEmail); return(RedirectToAction("MessageSuccess")); } return(View(messages)); }