Search code examples
rgmailgmail-apigmail-addons

Extracting emails from a gmail account with gmailr


I recently learned how to send emails in R with gmailr.

gmailr::send_message(mime(from = "email1@gmail.com", 
            to = "email2@gmail.com",
            subject = "The Great Subject", 
            body = "Hello buddy. How are you?"))

Now, suppose I have the account email2@gmail.com and I would like to get the body of this message I received. How can I do that in R? Thank you for your help and suggestions.


Solution

  • Based on chinsoon12's suggestion, I got the body of the email with

    A <- messages("The Great Subject",
        include_spam_trash = FALSE)
    message(id = A[[1]]$"messages"[[1]]$"id")$snippet
    

    I hope it helps you.