title: Send Generated Pdf as Email Attachment Asp.NetCore
body: <p>I am using Rotativa to convert my view to pdf. I would like to send that generated pdf as an email attachment (without having to download it first to disk). I've been following a bunch of tutorials to do this but I just keep going round in circles. I would much appreciate any help I can get.</p>
  <pre><code>public async Task&lt;IActionResult&gt;SomeReport()
  {
  ...
  return new ViewAsPdf (report)
  }
  return view();
  
  
  MemoryStream memoryStream = new MemoryStream();
  
  MimeMessage msg = new MimeMessage();
  MailboxAddress from = new MailboxAddress (&quot;Name&quot;, &quot;emailAddress&quot;)
  msg.From.Add(from);
  MailboxAddress to = new MailboxAddress (&quot;Name&quot;, &quot;emailAddress&quot;)
  msg.From.Add(to);
  BodyBuilder bd = new BodyBuilder();
  bb.HtmlBody =&quot;some text&quot;;
  bb.Attachments.Add(&quot;attachmentName&quot;, new MemoryStream());
  msg.Body = bb.ToMessageBody();
  SmtpClient smtp = new SmtpClient();
  smtp.Connect(&quot;smtp.gmail.com&quot;,465, true);
  smtp.Authenticate(&quot;emailAddress&quot;, &quot;Pwd&quot;);
  smtp.Send(msg);
  smtp.Disconnect(true);
  smtp.Dispose();
  </code></pre>
  <p>Edit</p>
  <pre><code>Parent View from which Email is sent
  
  @Model MyProject.Models.EntityViewModel 
  &lt;a asp-action= &quot;SendPdfMail&quot; asp-controller =&quot;Student&quot; asp-route-id = &quot;@Model.Student.StudentId&quot;&gt;Email&lt;/a&gt;
   ...
  
  
  SendPdfMail action in Student Controller
  public async Task&lt;IActionResult&gt; SendPdfMail(string id)
  {  
    var student = await context.Student. Where(s =&gt; s.StudentId == id);
    if (student != null)
    {
     ...
     var viewAsPdf = new ViewAsPdf(&quot;MyPdfView&quot;, new{route = id})
    {      
             Model = new EntityViewModel(),
              FileName = PdfFileName,
  
          ...
      }
     }
      };
  </code></pre>