Git Product home page Git Product logo

gmailr's Introduction

gmailr

CRAN status R-CMD-check Codecov test coverage

Exposing the Gmail API from R.

Installation

Install the released version of gmailr from CRAN:

install.packages("gmailr")

Or install the development version from GitHub with:

# install.packages("pak")
pak::pak("r-lib/gmailr")

Attach gmailr

library(gmailr)

Setup and auth

In order to use gmailr, you must provide your own OAuth client. This is documented in the article Set up an OAuth client. The article goes deeply into how to create an OAuth client and also how to configure it for gmailr’s use. If you already have an OAuth client or know how to create one, the help topics for ?gm_auth_configure and ?gm_default_oauth_client are more concise resources for just the client configuration piece.

Configuring an OAuth client is step 1 of 2 for getting ready to use gmailr. Step 2 is to complete the so-called “OAuth dance”, which is triggered automatically upon first need. You are taken to a web browser, where you must select or login as the Google user you want to use (authenticate yourself) and give your OAuth client permission to do Gmail stuff on your behalf (authorize). The OAuth dance does not (necessarily) need to be repeated in subsequent sessions. See ?gm_auth if these defaults aren’t appropriate for your use case and you’d like to take more control.

You can call gm_profile() to confirm that you are using the intended Google identity.

Compose and send an email

Create a new email with gm_mime() and build it up from parts, using helper functions like gm_to() and gm_subject().

test_email <-
  gm_mime() |>
  gm_to("PUT_A_VALID_EMAIL_ADDRESS_THAT_YOU_CAN_CHECK_HERE") |>
  gm_from("PUT_THE_GMAIL_ADDRESS_ASSOCIATED_WITH_YOUR_GOOGLE_ACCOUNT_HERE") |>
  gm_subject("this is just a gmailr test") |>
  gm_text_body("Can you hear me now?")

When developing the message, you might want to use gm_create_draft(), if you’d like to view a draft and verify that it’s formatted as you expect. Then you can send the draft with gm_send_draft() or send the original MIME message with gm_send_message().

# Verify it looks correct, i.e. look at your Gmail drafts in the browser
d <- gm_create_draft(test_email)

# If all is good with your draft, then you can send the existing draft
gm_send_draft(d)
#> Draft Id: 189033f7e08ead50 
#> NULL

# or the existing MIME message
gm_send_message(test_email)
#> Id: 189033f816495611

Read email

You can retrieve all email threads with gm_threads() or retrieve a specific thread with gm_thread(). You can then isolate a specific message and access its parts.

# view recent threads
my_threads <- gm_threads(num_results = 10)

# retrieve the latest thread by retrieving the first ID
latest_thread <- gm_thread(gm_id(my_threads)[[1]])

# messages in the thread will now be in a list
# retrieve parts of a specific message with the accessors
my_msg <- latest_thread$messages[[1]]

gm_date(my_msg)
#> [1] "Wed, 28 Jun 2023 11:24:00 -0700"
gm_subject(my_msg)
#> [1] "this is just a gmailr test"
gm_body(my_msg)
#> [[1]]
#> [1] "Can you hear me now?\r\n"

Where to learn more

More details are available in the Get started article and in gmailr’s other articles.

Policies

Privacy policy

gmailr's People

Contributors

absuag avatar alkashef avatar batpigandme avatar ismayc avatar jcheng5 avatar jennybc avatar jimhester avatar jlegewie avatar kazuya030 avatar lawremi avatar lwjohnst86 avatar maelle avatar obarisk avatar prithajnath avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gmailr's Issues

Send mail/Drafts

Hi,

Unless I missed it, I couldn't find a way in gmailr to create new emails. From https://developers.google.com/gmail/api/v1/reference/users/drafts/create it seems to me that the Google API does support creating new drafts. I don't know how hard it would be, but if something like a create_draft() function was added, then together with send_draft() we could send emails from gmailr. That would then open up to the use case that @kbroman talked about in his blog.

@kwbroman you should also check out https://t.co/11t6IA4bfQ

— Hadley Wickham (@hadleywickham) September 3, 2014
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>

Cheers,
Leo

Run gmailr in Linux

Hello Jim,

My name is Todd Mamiya, and I am trying to run gmailr in a command line linux environment. I am stuck at authentication in browser, since there is no browser. Is there any way to run gmailr from a linux command line? I love gmailr btw, great work!

Todd-

Use `edit()` to write emails

Maybe the nicest thing would be to have gmailr populate and then parse template ala

To: 
From: 
Subject: 

Then you could just fill in the fields and the rest.

Parse HTML content from the email

What is the best way to parse out the HTML for an email that includes HTML in the payload?

I am attempting this, but the results are not what I would have expected.

email = message(msg_ids[7], format = "full")
email_payload = email$payload
email_text = email_payload$parts[[1]]$body$data
email_html = email_payload$parts[[2]]$body$data
library(RCurl)
email_text_parsed = base64Decode(email_text)
email_html_parsed = base64Decode(email_html)

The text parsing appears to work ok, but the HTML doesn't appear to parse properly.

Attachment

Hello Jim,

Thank you so much for the wondeful package, I have a question:

How do you add attachments to these emails? I have attempted to add it in the mime statement below, however have been unsuccessful. Any direction/help would be Amazing.

test_email <- mime(
To = "[email protected]",
From = "[email protected]",
Subject = "this is just a gmailr test",
body = "Can you hear me now?")

Thank you!

Todd-

Adding attachment obscures body of message.

Message contents inserted with text_body() or html_body are no longer visible when attach_file() is also used to attach a pdf. The issue seems to fixable by inserting an apparently missing boundary line before the text section.

Change default authentication settings for gmail_auth

Hi Jim,

Thanks for your work on this awesome package.

The first time I used gmail_auth, I selected "2", indicating that I would like the package to authenticate in a pop-up window each time it is run. I now would like to run an automated script that uses gmailr from the command line and would like to change my preference to "1" so that no window pops up. Past comments insinuate that I could use a .httr-oauth file to specify my credentials, but I could not find a sample of one nor would I know where I would save it.

Any advice would be greatly appreciated. Thank you!
Matt

magrittr dependency

Is it really necessary to depend on magrittr? The pipe syntax seems orthogonal to an API package like gmailr. Should not the user be expected to library(magrittr) when they want access to the alternative syntax? Since the pipe theoretically applies to any API, is every library going to import and export the %>% symbol? That does not seem sustainable.

Peer certificate cannot be authenticated with given CA certificates

I am trying this, but I get a curl error. Is it because I have setup app specific passwords on my google account?

> install_github("jimhester/gmailr")
> install.packages("httpuv")
> library("gmailr")
> messages(search = "label:myLabel", user_id = user_id, num_results = 2)
Waiting for authentication in browser...
Press Esc/Ctrl + C to abort
Authentication complete.
Error in curl::curl_fetch_memory(url, handle = handle) : 
  Peer certificate cannot be authenticated with given CA certificates

and my setup information:

R version 3.2.2 (2015-08-14)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu precise (12.04.5 LTS)

> packageVersion("RCurl")
[1] '1.95.4.7'
> packageVersion("gmailr")
[1] '0.6.0'

I have tried:

to install libcurl4-openssl-dev and reinstall RCurl

sudo apt-get install libcurl4-openssl-dev
R
install.packages("RCurl")

but in vain

message(...,format=c("minimal","full","raw")) don't work

I'm able to search messages('query') and retrieve message IDs from the list, but then retrieving them with message(messageID, format="raw"), format="full" or format="minimal" don't give me any more than the subject line.

> message('**************', format = "raw")
[1] "Id: **************\nTo: \nFrom: \nDate: \nSubject: \n"
> message('**************', format = "full")
[1] "Id: **************\nTo: cs****@aon.at\nFrom: Louis Maddox \nDate: Wed, 4 Feb 2015 03:15:31 +0000\nSubject: xps failed to compile\n"
> message('**************', format = "minimal")
[1] "Id: **************\nTo: \nFrom: \nDate: \nSubject: \n"

Am I missing something perhaps, or is this part of the API wrapper a work in progress?

NAMESPACE is not updated

Hello,

Now that issue #1 is fixed, I tried testing the messages() function and ran into an error.

> library(gmailr)
> gmail_auth("new-installed-applications.json")
> x <- messages("getting started")
Error: could not find function "messages"

Turns out that even though the roxygen2 tag specifies to export this function, it was not exported in the NAMESPACE.

Cheers,
Leo

Label_id not working

I may be doing something wrong, but I specify a label id in messages and it retrieves a mixture of what is in that label and what is in the inbox. So label is not working exclusively.

base::message() is masked

I realize I do get notified that gmailr::message() masks base::message() when I load gmailr. But I wonder if this is too basic a function to mask? I guess other packages are protected, since they'll be using base::message(), but ... maybe I'm not the only one who uses message() in scripts?

This is what I get with the CRAN version.

library(gmailr)
message("Hey I'm a message")
#> Error in get_token(): If this is your first time using Gmailr, Please
#> 
#> - Register a new project at https://cloud.google.com/console#/project
#> - Navigate to `APIs`
#>   - Switch the Gmail API status to `On`, and other API status to `Off`
#> - Navigate to `APIs & auth->Consent screen`
#>   - Name your application
#>   - Select an email address for the application
#>   - Other fields can be left blank
#> - Navigate to `APIs & auth->Credentials`
#>   - Create a new client ID
#>     - Application Type: Installed Application
#>     - Installed Application Type: Other
#>   - Download the Client ID JSON - can be renamed!
#> - Use the downloaded JSON file as input to `gmail_auth()`
devtools::session_info()
#> Session info --------------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.2.2 (2015-08-14)
#>  system   x86_64, darwin13.4.0        
#>  ui       RStudio (0.99.747)          
#>  language (EN)                        
#>  collate  en_US.UTF-8                 
#>  tz       America/Vancouver           
#>  date     2015-11-01
#> Packages ------------------------------------------------------------------
#>  package   * version    date       source                            
#>  base64enc   0.1-3      2015-07-28 CRAN (R 3.2.0)                    
#>  clipr       0.1.1      2015-09-04 CRAN (R 3.2.0)                    
#>  curl        0.9.3      2015-08-25 CRAN (R 3.2.0)                    
#>  devtools    1.9.1.9000 2015-11-01 Github (hadley/devtools@89e7bfd)  
#>  digest      0.6.8      2014-12-31 CRAN (R 3.2.0)                    
#>  evaluate    0.8        2015-09-18 CRAN (R 3.2.0)                    
#>  formatR     1.2        2015-04-21 CRAN (R 3.2.0)                    
#>  gmailr    * 0.6.0      2014-12-04 CRAN (R 3.2.0)                    
#>  htmltools   0.2.6      2014-09-08 CRAN (R 3.2.0)                    
#>  httr        1.0.0      2015-06-25 CRAN (R 3.2.0)                    
#>  knitr       1.11       2015-08-14 CRAN (R 3.2.1)                    
#>  magrittr    1.5        2014-11-22 CRAN (R 3.2.0)                    
#>  memoise     0.2.1      2014-04-22 CRAN (R 3.2.0)                    
#>  R6          2.1.1      2015-08-19 CRAN (R 3.2.0)                    
#>  reprex      0.0.0.9001 2015-09-14 local                             
#>  rmarkdown   0.8        2015-08-30 CRAN (R 3.2.1)                    
#>  rsconnect   0.4.1.4    2015-09-15 Github (rstudio/rsconnect@6ea6977)
#>  stringi     1.0-1      2015-10-22 CRAN (R 3.2.0)                    
#>  stringr     1.0.0.9000 2015-10-27 Github (hadley/stringr@3813041)

And here's with 4c07595, in a directory with valid token in .httr-oauth:

library(gmailr)
message("Hey I'm a message")
#> Error in gmailr_query(GET, location, user_id, class, ...): cannot change value of locked binding for '.last_response'
devtools::session_info()
#> ALL SAME AS ABOVE EXCEPT FOR:
#>  gmailr    * 0.6.0      2015-11-02 Github (jimhester/gmailr@4c07595) 

Provide installation instructions?

Right now, to install gmailr from GitHub, you must have a very recent version of devtools or you get this error:

Error: Malformed remote specification 'gaborcsardi/argufy'

Maybe until the Remotes feature is present in CRAN devtools, you could mention this in the README?

cannot send mail

For my class, I've been using the CRAN version but thought I'd try dev version today. But I cannot seem to send mail. Below I'm using your built-in global project (although I don't when sending course email for real), and have already cached an auth token in working directory here.

library(gmailr)

text_msg <- mime() %>%
  to("[email protected]") %>%
  from("[email protected]") %>%
  text_body("default credentials, to and from [email protected]")

ret <- text_msg %>%
  send_message()
#> Error in gmailr_query(POST, location, user_id, class, ...): cannot change value of locked binding for '.last_response'

## try the example from send_message()
send_message(mime(from="[email protected]", to="[email protected]",
                  subject="hello", "how are you doing?"))
#> Error in gmailr_query(POST, location, user_id, class, ...): cannot change value of locked binding for '.last_response'

session_info("gmailr")
#> Session info --------------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.2.2 (2015-08-14)
#>  system   x86_64, darwin13.4.0        
#>  ui       RStudio (0.99.747)          
#>  language (EN)                        
#>  collate  en_US.UTF-8                 
#>  tz       America/Vancouver           
#>  date     2015-11-01
#> Packages ------------------------------------------------------------------
#>  package   * version    date       source                             
#>  argufy      1.0.0      2015-10-06 Github (gaborcsardi/argufy@f7cfeef)
#>  base64enc   0.1-3      2015-07-28 CRAN (R 3.2.0)                     
#>  curl        0.9.3      2015-08-25 CRAN (R 3.2.0)                     
#>  digest      0.6.8      2014-12-31 CRAN (R 3.2.0)                     
#>  gmailr    * 0.6.0      2015-11-01 Github (jimhester/gmailr@4c07595)  
#>  httr        1.0.0      2015-06-25 CRAN (R 3.2.0)                     
#>  jsonlite    0.9.17     2015-09-06 CRAN (R 3.2.0)                     
#>  magrittr    1.5        2014-11-22 CRAN (R 3.2.0)                     
#>  mime        0.4        2015-09-03 CRAN (R 3.2.0)                     
#>  R6          2.1.1      2015-08-19 CRAN (R 3.2.0)                     
#>  stringi     1.0-1      2015-10-22 CRAN (R 3.2.0)                     
#>  stringr     1.0.0.9000 2015-10-27 Github (hadley/stringr@3813041)

Bounce email when following

Hi,

I have some problems with the tutorial on how to send emails with your gmailr package.

The code below returns a bounce mail due to the html_body part. Just if I remove it the email is sent correctly, but without body. Also text_body does not work for me.

Also, can you advise me on how to send an attachment. (I tried %>% attach_file("iris.csv") , but that also results in a bounce email.)

test_email <- mime() %>%
 to("[email protected]") %>%
 from("[email protected]") %>%
 subject("This is a subject") %>%
 html_body("<html><body>I wish <b>this</b> was bold</body></html>")

Thanks for the awesome package.

Marco

Bounce reply send_message()

I created a new gmail acount and then followed the setup instructions here.

Running gmail_auth() with the .json file, opens a webpage and then I approve that credential.

library(gmailr)

msg <-  mime() %>%
from("[email protected]") %>%
to("[email protected]") %>%
text_body("Please don't reject my package")

send_message(msg)

This just returns a bounce reply to the notify.jwr account that says message not sent. I apologize for not having a MWE.

inserting messages into existing threads

This is possible with the threadId parameter in the API, however you have to set the References, In-Reply-To and Subject headers properly. It would be nice to make this automatic, i.e. by passing a function the thread object and the message, and have it modify it appropriately.

How to read zip attachment that has cvs in it

I receive an email everyday with a fixed subject line that has a attachment in a zip format which contains a csv (.csv.gz format)
I have successfully set up this package and it's working fine.
Can you please help me further. I want to read my csv in R.

Thanks in advance.

messages(...,num_results = 9999) results in too many messages

I thought num_results would just give me all results if the number was greater than the number of matches, but somehow i get exactly the number of results, of course with many duplicate records.

The documentation is sparse, so how exactly is num_results supposed to be used?
Or to put it simply, how can I get all messages in certain label?

as_enum issues

There are several functions which use the as_enum assertion, which does not resolve the default when the argument is left missing. These include message(), insert_message(), import_message(), send_message(), draft(), create_draft(), and send_draft().

HTML File as message body

I have a HTML file that I want to be message body of the emails I am sending.
How to I insert my HTML file in the code

loading gmailr library breaks View in RStudio

due to the body() function?

df = data.frame(a = c(1,2,3), b = c(3,4,5))
View(df)
Error in View : no applicable method for 'body' applied to an object of class "function"
Error in UseMethod("body") :
no applicable method for 'body' applied to an object of class "function"
traceback()
12: body(object)
11: .rs.resolveAliasedSymbol(object)
10: .rs.getAnywhere(name, src)
9: args(obj)
8: print(args(obj))
7: eval(expr, envir, enclos)
6: eval(expr, pf)
5: withVisible(eval(expr, pf))
4: evalVis(expr)
3: capture.output(print(args(obj)))
2: .rs.getSignature(.rs.getAnywhere(name, src))
1: (function (name, src)
{
if (identical(src, ""))
src <- NULL
result <- .rs.getSignature(.rs.getAnywhere(name, src))
result <- sub("function ", "", result)
.rs.scalar(result)
})("traceback", "package:base")

Body is blank after attaching file

I haven't actually come across an example which does this but I was hoping that this would work:
write.csv(file = "iris.csv", iris)

mime() %>%
to('[email protected]') %>%
from("[email protected]") %>%
subject("Test subject") %>%
text_body("Test body") %>%
attach_file("iris.csv") %>%
send_message()

Although the email is sent with the attachment, the body is not included in the email. It seems to be dropped entirely from the message when it's sent although the object that goes into send_message() still includes the body part. It doesn't work with html_body() either, attaching multiple files works fine.

This email does include the body:

mime() %>%
to('[email protected]') %>%
from("[email protected]") %>%
subject("Test subject") %>%
text_body("Test body") %>%
#attach_file("iris.csv") %>%
send_message()

Unable to send mail

I've tried everything I know, ranging from creating a new Project (w/ new secret and key) to installing from GitHub and using the built-in defaults. Before I provide a detailed example: are you able to send a test email with gmailr these days? I am wondering if it is a transient problem with the Gmail API, although I see no external evidence of that. BTW the "Download JSON" feature is not working in Developers Console right now, although I believe I know how to workaround that.

Using the CRAN version with my own secret and ID, I am getting Error in send_message(test_email) : client error: (400) Bad Request. Installling from GitHub and using my own or built-in default credentials, I am getting: Error: length(url) == 1 is not TRUE.

Any idea what I'm bumping up against? Do you recommend I use the CRAN version or GitHub version and, if GitHub, which SHA?

cannot extract the body of a message

I have tried:

> y = gmailr::message("15285bb691e1a2b4", user_id = user_id, format = c("full", "minimal", "raw")[1])
# this works and returns a valid gmailr message.

> y$payload$mimeType
[1] "text/html"

> y$payload$body # this returns a format I don't know how to read (64 encoding I guess) 

> y$payload$headers[[25]]
$name
[1] "Mime-Version"
$value
[1] "1.0"

> y$payload$headers[[26]]
$name
[1] "Content-Transfer-Encoding"
$value
[1] "base64"

> RCurl::base64Decode(txt = y$payload$body$data) # this returns a valid html txt, however only the first part is there, using a online tool such as https://www.base64decode.org/, I can get the entire body

#but all the following return an empty list()
y_body = gmailr::body(y, type = "html")
y_body = gmailr::body(y, type = NULL)
y_body = gmailr::body(y, type = "text/plain")

Any help would be welcome:

  1. is gmailr::body supposed to do the 64 decoding?
  2. is there an alternative to get the full body in html?

Thank you

Send Message With Attachment Problem

I am trying to run the following

write_csv(iris, 'iris.csv')
test_email <- mime(to = "[email protected]",
from = "[email protected]",
subject = "This is a test email",
body = "Hola")
test_email <- attach_file(test_email, 'iris.csv')
send_message(test_email %>% attach_file('iris.csv'), type ="multipart")

BUT, the email gets bounced and the iris.csv is not attached in the original message.

Where to add documentation?

I've just used gmailr for the first time in a long time and it was a rough start. But it had a happy ending! If I want to propose some enhancements to documentation, which is your preferred target: README or vignette?

HTML email using GMAILR - body is blank

hi @jimhester - this is in response to your twitter suggestion. I am having a hard time getting
body_html to properly send email in r using GMAILR. I have tried numerous different approaches and the result is always the same - an email with no body content when i use html_body.

I presume that I am doing something wrong however i can not figure out what that might be. I just installed GMAILR the other day. I am running R 3.2.3.

suppressPackageStartupMessages(library(gmailr))
# custom json file
gmail_auth("data-institute-email.json", scope = 'compose')

## the code below sends a nice text formatted email
## the $body slot is populated correctly in test_email
test_email <- mime(
  To = "[email protected]",
  From = "[email protected]",
  Subject = "this is just a gmailr test",
  body = "Can you hear me now?")

The next chunk returns a blank email and the $body slot in test_email is also blank

# this returns a BLANK email
test_email <- mime(
  To = "[email protected]",
  From = "[email protected]",
  Subject = "this is just a gmailr test",
  html_body = "Can <b>you hear</b> me now?", type = "text/html")

# this also sends a blank email
test_email <- mime(
  To = "[email protected]",
  From = "[email protected]",
  Subject = "this is just a gmailr test",
  html_body = "<html><body>Can <b>you hear</b> me now?</body></html>")

to send the email (this works fine)

ret_val <- send_message(test_email)

Any suggestions that you have area greatly appreciated!
Leah

Getting started

Hello,

I am probably missing something obvious, but I am having trouble getting started with using gmailr.

  • Went to https://cloud.google.com/console#/project
  • I created a project, called it "Access-gmailr"
  • Opened the project. Then under "APIs & Auth" and in the sub-menu "API" I enabled the Gmail API. That automatically enabled a couple other APIs as shown below.
    screen shot 2014-09-03 at 1 31 15 pm
  • Then under "APIs & Auth" and in the sub-menu "Credentials" I downloaded the "Compute Engine App Engine" json. Tried using it and got a 400 error.
    screen shot 2014-09-03 at 1 27 52 pm
  • Also under "APIs & Auth" and in the sub-menu "Credentials" created a new client ID and selected the "service account" option. This didn't work either and lead to another 400 error.
    screen shot 2014-09-03 at 1 36 44 pm

So, hm... what am I missing?

I did check that under the "Permissions" menu all the service accounts have the permission to edit. The Gmail API auth page didn't help me either.

Thanks!

> sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-apple-darwin10.8.0 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] gmailr_0.0.1

loaded via a namespace (and not attached):
[1] base64enc_0.1-2 httpuv_1.3.0    httr_0.4        jsonlite_0.9.10 Rcpp_0.11.2     RCurl_1.95-4.3  stringr_0.6.2   tools_3.1.0 

Multiple Msgs from Same Thread Not Showing

Hi there,

I am attempting to extract multiple e-mails from the same thread. I am using first messages('search query'), then looping through each message_id to extract the body of the message.

When doing this within the same thread of messages, I am only able to open the first message. This first message_id also happens to be the same id as the thread. Coincidence?
Anyway, when I go to extract a message, the one in which I am the only recipient works perfectly.When there are multiple recipients on the list, I am not able to extract the full message. The body of the message is blank.

I believe the issue could be that there are multiple recipients of the e-mail. Am I allowed to extract the data if I am not the only one on the recipients list?

Thank you!

has_class() should always call is()

The is() function is the only reliable way to check inheritance in R, because it handles S3/S4 objects and S4 classes. inherits() will break for an S3 object tested against, for example, a union of basic classes.

> setClassUnion("integerORfactor", c("integer", "factor"))
> inherits(factor(), "integerORfactor")
[1] FALSE
> is(factor(), "integerORfactor")
[1] TRUE

Probably can just get rid of has_class() and call is() directly, because argufy does not do what you want when the assertion is a call.

client error: (403) Forbidden. Change in Gmail API?

Hi @jimhester. I'm new in this package. I installed this package and explored their function, other function work well for me. However sending a message gave me an error.

I tried using this code

msg <- mime() %>%
from("[email protected]") %>%
to("[email protected]") %>%
text_body("Please don't reject my package")

send_message(msg)

However this error message Error in send_message(msg) : client error: (403) Forbidden

It seems like this is a "new" (From Octubre 2014) error because Gmail's API changed.

http://stackoverflow.com/questions/26135310/gmail-api-returns-403-error-code-and-delegation-denied-for-user-email

get character encoding from content-type

After decoding the message payload, gmailr could extract the charset from the Content-Type header. By default on the web, this is iso-8859-1, which R calls "latin1". That could be set on the string, e.g.,

Encoding(x) <- "latin1"

But then again, I'm not sure where that actually helps, since R always displays and writes strings in the current locale, so things get weird.

improve the read-me file?

It is not clear whether it is free to create a new project. (Google tells me I have 300USD free of data usage?) Is gmailr consuming non free data usage from google?

Thank you!

magrittr mime issue

After setting up my own project, enabling the GMail API, getting an OAuth file, and creating a "full" scope credential within R, I tried to send my first e-mail via R using the magrittr example given. However, the recipient did not get the e-mail. Instead, I received a nondescript error message informing me my email bounced.

Puzzled, I tried it again about 30 minutes later. Same result.

I opted to directly use the mime and send_message function. This lead to the e-mail being sent and received without any errors.

I've created a simple working example that only needs e-mail lines to be changed slightly to test. Within this example, the headers between the two messages are considerably different. I'm wondering if there is a header issue that is similar to http://stackoverflow.com/questions/28122074/gmail-api-emails-bouncing when using the ma

install.packages("gmailr")
library("gmailr")

text_email = mime(
  To = "[email protected]",
  From = "[email protected]",
  Subject = "GMailr demo email",
  body = "Will this message bounce?")

strwrap(as.character(text_email))

[1] "MIME-Version: 1.0\r Date: Sat, 14 Nov 2015 11:56:03 GMT\r To: [email protected]\r From: [email protected]\r Subject: GMailr"
[2] "demo email\r Content-Type: text/plain\r Content-Disposition: inline\r \r Will this message bounce?\r"                                                  

mime() %>%
  from("[email protected]") %>%
  to("[email protected]") %>%
  subject("GMailr demo email") %>%
  text_body("Will this message bounce?") -> text_msg

strwrap(as.character(text_msg))

[1] "MIME-Version: 1.0\r Date: Sat, 14 Nov 2015 11:56:03 GMT\r From: [email protected]\r To: [email protected]\r Subject:"  
[2] "GMailr demo email\r Content-Type: multipart/mixed; boundary=89b12c388f0c424d5c3429c454ab9126\r Content-Disposition: inline\r"      
[3] "--89b12c388f0c424d5c3429c454ab9126\r MIME-Version: 1.0\r Date: Sat, 14 Nov 2015 11:56:03 GMT\r Content-Type: text/plain;"       
[4] "charset=utf-8; format=flowed\r Content-Transfer-Encoding: quoted-printable\r Content-Disposition: inline\r \r Will this message"
[5] "bounce?\r --89b12c388f0c424d5c3429c454ab9126--\r" 


# Sails through and has status code of 200
send_message(text_email)$status_code

# Bounces but has status code of 200
send_message(text_msg)$status_code

Support google 'service' applications

It appears that gmailr currently only supports 'installed/native' application. You should:

  • state this in the readme file and the vignettes ( I burned a bunch of time trying to figure this out.)

OR

  • also support 'service' application. It is an easy change and only matters how you parse and send the JSON file.

Created Email that won't actually send

Thank you for making this package; it's pretty cool! I'm new at this though and am making some error that I can't solve. I've looked through the examples and succeeded in sending the basic email in the tutorial. However, when I try and attach a pdf file to the email and then send it, I wind up getting the email to bounce. If I open my email account, I can see the attachment is properly appended. What I did notice is that the body now has a large text string attached to it. Here is an example:

Here is the message body--8935280f304c8e1e050811c564e08949--

Here is the syntax I used:

email_body <- mime(
  To = "[[email protected]]",
  From = "[[email protected]]]",
  body = "Here is the message body"
)

email_body %>%
  subject("Testing to see if I can get an attachment through") %>%
  attach_file('MyPdfFile.pdf') -> file_attachment

send_message(file_attachment)

Here is the session info

> sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] RGoogleAnalytics_0.1.1 lubridate_1.3.3        httpuv_1.3.2           gridExtra_0.9.1        plyr_1.8.1            
 [6] ggplot2_1.0.1          rjson_0.2.15           RCurl_1.95-4.5         bitops_1.0-6           gmailr_0.6.0          
[11] httr_0.6.1             mailR_0.4.1            sendmailR_1.2-1        sqldf_0.4-10           RSQLite_1.0.0         
[16] DBI_0.3.1              gsubfn_0.6-6           proto_0.3-10           reshape_0.8.5          dplyr_0.4.1           

loaded via a namespace (and not attached):
 [1] assertthat_0.1    base64enc_0.1-2   chron_2.3-45      colorspace_1.2-4  digest_0.6.8      gtable_0.1.2     
 [7] jsonlite_0.9.14   magrittr_1.5      MASS_7.3-31       memoise_0.2.1     mime_0.2          munsell_0.4.2    
[13] parallel_3.1.0    R.methodsS3_1.7.0 R.oo_1.19.0       R.utils_2.0.0     R6_2.0.1          Rcpp_0.11.4      
[19] reshape2_1.4.1    rJava_0.9-6       scales_0.2.4      stringr_0.6.2     tcltk_3.1.0       tools_3.1.0  

Thank you in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.