How do you add a PDF attachment to an email? Goal: I need to send an email with a pdf attachment in Drupal 8.

Progress

I am able to send an email with subject and message but have never been able to get the attachment. When I turn on the logic to attach the file to the email, the email never gets sent but the mail service returns True as if the email was sent anyway. There are no errors and the logs say nothing. 

I have the following modules installed:


SMTP
MailSystem
MimeMail


What I've tried


Tried using $message['params']['files'][] = $params['attachments'] instead of $message['params']['attachments'][] = $params['attachments'] like some examples have recommended
Tried changing $file-&gt;uri to $file-&gt;filepath
Tried attaching the file like so:

$params['attachments']['filecontent'] = $this-&gt;generatePDF($foa_list);
$params['attachments']['filename'] = 'MyFormsOfAssistance.pdf';
$params['attachments']['filemime'] = 'application/pdf';

Tried attaching the file by path alone with an array:

$attachment = array(
    'filepath'=&gt;'sites/default/files/MyFormsOfAssistance.pdf',
);

$params['attachments'] = $attachment;

Tried attaching the file a different way:

$attachment = array(
    'filepath' =&gt; 'sites/default/files/MyFormsOfAssistance.pdf',
    'filename' =&gt; 'MyFormsOfAssistance.pdf',
    'filemime' =&gt; 'application/pdf'
);

$params['attachments'][] = $attachment;



Setup


There is email landing page in which a user enters the recipient's email address, subject for the email, and message for the email. 
When user clicks Send button, that data is routed to my Email Controller 
Email controller creates the pdf file, attempts to attach the pdf to the email, and then sends the email. 
I have the hook_mail() function defined in my module file. 


Here is the code for my Email Controller:

public function submit_email($foa_list = null) {
    $lang = "en";
    $email_to = "blah@blah.com";
    $params['subject'] = "Test subject";
    $params['body'] = "Test body";

    // -------------------- Attachment Logic -----------------------
    // Create pdf file and store file
    file_put_contents('sites/default/files/MyFormsOfAssistance.pdf', $this-&gt;generatePDF($foa_list));


    // Attach pdf file to email params
    $file = new \stdClass();
    $file-&gt;uri = 'sites/default/files/MyFormsOfAssistance.pdf';
    $file-&gt;filename = 'MyFormsOfAssistance.pdf';
    $file-&gt;filemime = 'application/pdf';
    $params['attachments'][] = $file;

    // Send email
    \Drupal::service('plugin.manager.mail')-&gt;mail('email', 'email', $email_to, $lang, $params);

    $response = new Response();
    $response-&gt;setContent("true");

    return $response;
}


Here is the hook_mail() code in my Email module file:

// Note that print_and_email is what my module is called.
function print_and_email_mail($key, &amp;$message, $params) {
    switch($key) {
        case 'email':
            $message['subject'] = $params['subject'];
            $message['body'][] = $params['body'];
            $message['headers'] = [
              'MIME-Version' =&gt; '1.0',
              'Content-Type' =&gt; 'text/html; charset=UTF-8; format=flowed; delsp=yes',
              'Content-Transfer-Encoding' =&gt; '8Bit',
              'X-Mailer' =&gt; 'Drupal',
            ];
            // $message['params']['files'][] = $params['attachments']; // Note: I have seen other examples implement attachments this way
            $message['params']['attachments'][] = $params['attachments'];
            break;
    } 
}


The Drupal 8 documentation isn't really helpful and I would like to be able to figure this out without installing SwiftMailer, like some sources have recommended. Really not sure why this isn't working as it has worked for others. What am I missing?
FINALLY! 4 weeks later... 

So the following code ended up working for me:

    $attachment = array(
        'filepath' =&gt; 'sites/default/files/MyFormsOfAssistance.pdf',
        'filename' =&gt; 'MyFormsOfAssistance.pdf',
        'filemime' =&gt; 'application/pdf'
    );


BUT, the key was that in the MailSystem Configuration I had to set the Formatter and Sender to "SMTP Mailer". MimeMail's config automatically pulled it's values from my SMTP's configuration.