title: sendmailR (Part2): Sending files as mail attachments
body: <p>Following the directions provided in <a href="https://stackoverflow.com/questions/3528947/sendmailr-submit-encoded-message-to-local-smtp-server">this</a> related question, I was able to send html formated mail messages. Now the question is this: How should I modify the following code, in order to attach one or more files (of any type) to this message?</p>
  
  <pre><code>library(sendmailR)
  
  from &lt;- "&lt;sendmailR@myserver.mycompany.com&gt;"
  to &lt;- c("&lt;someone@mycompany.com&gt;","&lt;anotherone@mycompany.com&gt;")
  subject &lt;- iconv("Message Title", to = "utf8")
  
  msg &lt;- "&lt;hr size='2' width='33%' style='text-align: left;'&gt;&lt;font size='2'&gt;
    &lt;i&gt;This email was sent automatically using &lt;a href='http://finzi.psych.upenn.edu/R/library/sendmailR/html/00Index.html' rel='nofollow' target='_blank'&gt;sendmailR&lt;/a&gt;.&lt;br&gt;
    Please do not reply directly to this e-mail.&lt;/i&gt;&lt;/font&gt;"
  
  msg &lt;- iconv(msg, to = "utf8")
  
  sapply(to,function(x) sendmail(from, x, subject, msg, control=list(smtpServer="###.###.###.###"), headers=list("Content-Type"="text/html; charset=UTF-8; format=flowed")))
  </code></pre>