title: Sending an email in MVC
body: <p>I have a method that returns a list of products from the database that I would like to send to a certain email address. The method I would like to send returns a list of items. There's a <code>ContactUs</code> formula that sends a message but from costumer to store owner that I'm considering using as a base. However the data I want to send as an email are only supposed to be sent to the storeowner email address without a sender.</p>
  
  <p>I want to send the list of products that is returned from this method:</p>
  
  <pre><code>public IList&lt;BestsellersReportLine&gt; DailyBestsellersReport()
  {
      OrderStatus os; 
      PaymentStatus? ps = null; 
      ShippingStatus ss;
      int billingCountryId = 0;
      int recordsToReturn = 999; 
      int orderBy = 1;
      int groupBy = 1;
  
      int? paymentStatusId = null;
      if (ps.HasValue)
          paymentStatusId = (int)ps.Value;
  
      // Specifies the time range for sold products/day
      var range = new
      {
          startTimeUtc = DateTime.Today.AddDays(-1),
                       endTimeUtc = DateTime.Today.AddSeconds(-1),
                       CreatedOnUtc = DateTime.Today.AddDays(-1),
      };
  
      var query1 = from opv in _opvRepository.Table
          join o in _orderRepository.Table on opv.OrderId equals o.Id
          join pv in _productVariantRepository.Table on opv.ProductVariantId equals pv.Id
          join p in _productRepository.Table on pv.ProductId equals p.Id
          where (o.CreatedOnUtc &gt;= range.startTimeUtc &amp;&amp; o.CreatedOnUtc &lt;= range.endTimeUtc) &amp;&amp;
          (!paymentStatusId.HasValue || paymentStatusId == o.PaymentStatusId)
          select opv;
  
      var query2 = groupBy == 1 ?
          //group by product variants
          from opv in query1
          group opv by opv.ProductVariantId into g
          select new
          {
              EntityId = g.Key,
                       TotalAmount = g.Sum(x =&gt; x.PriceExclTax),
                       TotalQuantity = g.Sum(x =&gt; x.Quantity),
          }
      :
          //group by products
          from opv in query1
          group opv by opv.ProductVariant.ProductId into g
          select new
          {
              EntityId = g.Key,
                       TotalAmount = g.Sum(x =&gt; x.PriceExclTax),
                       TotalQuantity = g.Sum(x =&gt; x.Quantity),
          }
      ;
  
      switch (orderBy)
      {
          case 1:
              {
                  query2 = query2.OrderByDescending(x =&gt; x.TotalQuantity);
              }
              break;
          case 2:
              {
                  query2 = query2.OrderByDescending(x =&gt; x.TotalAmount);
              }
              break;
          default:
              throw new ArgumentException("Wrong orderBy parameter", "orderBy");
      }
  
      if (recordsToReturn != 0 &amp;&amp; recordsToReturn != int.MaxValue)
          query2 = query2.Take(recordsToReturn);
  
      var result = query2.ToList().Select(x =&gt;
              {
              var reportLine = new BestsellersReportLine()
              {
              EntityId = x.EntityId,
              TotalAmount = x.TotalAmount,
              TotalQuantity = x.TotalQuantity
              };
              return reportLine;
  
  
              }).ToList();
  
      //return result;
      return result.OrderBy(opv =&gt; opv.TotalQuantity).ToList();
  }
  </code></pre>
  
  <p>As an email into this method:</p>
  
  <pre><code>[HttpPost, ActionName("ContactUs")]
  [CaptchaValidator]
  public ActionResult ContactUsSend(ContactUsModel model, bool captchaValid)
  {
      //validate CAPTCHA
      if (_captchaSettings.Enabled &amp;&amp; _captchaSettings.ShowOnContactUsPage &amp;&amp; !captchaValid)
      {
          ModelState.AddModelError("", _localizationService.GetResource("Common.WrongCaptcha"));
      }
  
      if (ModelState.IsValid)
      {
          string email = model.Email.Trim();
          string fullName = model.FullName;
          string subject = string.Format(_localizationService.GetResource("ContactUs.EmailSubject"), _storeInformationSettings.StoreName);
  
          var emailAccount = _emailAccountService.GetEmailAccountById(_emailAccountSettings.DefaultEmailAccountId);
          if (emailAccount == null)
              emailAccount = _emailAccountService.GetAllEmailAccounts().FirstOrDefault();
  
          string from = null;
          string fromName = null;
          string body = Core.Html.HtmlHelper.FormatText(model.Enquiry, false, true, false, false, false, false);
          //required for some SMTP servers
          if (_commonSettings.UseSystemEmailForContactUsForm)
          {
              from = emailAccount.Email;
              fromName = emailAccount.DisplayName;
              body = string.Format("&lt;strong&gt;From&lt;/strong&gt;: {0} - {1}&lt;br /&gt;&lt;br /&gt;{2}",
                      Server.HtmlEncode(fullName),
                      Server.HtmlEncode(email), body);
          }
          else
          {
              from = email;
              fromName = fullName;
          }
          _queuedEmailService.InsertQueuedEmail(new QueuedEmail()
          {
              From = from,
              FromName = fromName,
              To = emailAccount.Email,
              ToName = emailAccount.DisplayName,
              Priority = 5,
              Subject = subject,
              Body = body,
              CreatedOnUtc = DateTime.UtcNow,
              EmailAccountId = emailAccount.Id
          });
  
          model.SuccessfullySent = true;
          model.Result = _localizationService.GetResource("ContactUs.YourEnquiryHasBeenSent");
  
          //activity log
          _customerActivityService.InsertActivity("PublicStore.ContactUs", _localizationService.GetResource("ActivityLog.PublicStore.ContactUs"));
  
          return View(model);
      }
  
      model.DisplayCaptcha = _captchaSettings.Enabled &amp;&amp; _captchaSettings.ShowOnContactUsPage;
      return View(model);
  }
  </code></pre>
  
  <p>Note: ContactUs -method is a default method in NopCommerce, iv'e tried changing a few things but im not getting annywhere. I just need to send the list of products retrieved from the database through "DailyBestsellersReport method" to the email adress of the store owner.</p>
  
  <p>In simple theory I would like to do something like this:</p>
  
  <pre><code>[HttpPost, ActionName("Bestsellers")]
  [CaptchaValidator]
  public ActionResult SendBestSellersList(BestSellersReportLine model)
  {
      DailyBestsellersReport();
  }
  </code></pre>