First we will construct a simple text only message
You can convert the message to a properly formatted MIME message using
##  "MIME-Version: 1.0\r Date: Thu, 23 May 2019 15:33:24 GMT\r To:" ##  "firstname.lastname@example.org\r From: email@example.com\r Content-Type:" ##  "multipart/mixed; boundary=f77c961b529f4915bcb69f30f3583203\r" ##  "Content-Disposition: inline\r \r MIME-Version: 1.0\r Date: Thu, 23" ##  "May 2019 15:33:24 GMT\r Content-Type: text/plain; charset=utf-8;" ##  "format=flowed\r Content-Transfer-Encoding: quoted-printable\r" ##  "Content-Disposition: inline\r \r Gmailr is a very handy package!\r" ##  "--f77c961b529f4915bcb69f30f3583203--\r"
You can also construct html messages. It is customary to provide a text only message along with the html message, but with modern email clients this is not strictly necessary.
You can add attachments to your message in two ways.
attach_file(). The mime type is automatically guessed by
mime::guess_type, or you can specify it yourself with the
attach_part()to attach the binary data to your file.
You can upload any mime message into your gmail drafts using
create_draft(). Be sure to give yourself at least
compose permissions first.
This inserts the message directly into your mailbox, bypassing gmail’s default scanning and classification algorithms.
It is possible to have a high-functioning Google account that does not have Gmail enabled. For example, your account might be fully operational with respect to Google Drive and yet have no mail capabilities. Such an account cannot be used with the Gmail API and therefore with
gmailr. However, you will still be able to complete the
gmailr authorization process via
gmail_auth(). The problem will only reveal itself upon the first attempt to use the API and it will look something like this:
Error in gmailr_POST(c("messages", "send"), user_id, class = "gmail_message", : Gmail API error: 400 Mail service not enabled
You can confirm the account’s lack of mail capability by visiting https://mail.google.com/mail/ while logged in. If you don’t already have Gmail, this link gives you the option of adding mail to your existing account or creating a new, mail-capable account.