r-lib / gmailr

Access the Gmail RESTful API from R.
https://gmailr.r-lib.org
Other
229 stars 56 forks source link

Tooling around draft + send workflow #158

Open hadley opened 3 years ago

hadley commented 3 years ago

It's really reassuring to first generate a drafts and then send those drafts. It would be nice to have a little tooling around this workflow, particularly if you're sending a few hundred emails and want to be able to easily resume if anything bad happens part way through.

At a minimum, I think this just needs gm_create_drafts() (takes a list of mimes) and gm_send_drafts() (takes return value of gm_create_drafts()). Empirically it also seems like you need to sleep between each call to gm_send_draft() in order to avoid this error:

{
  "error": {
    "code": 400,
    "message": "Precondition check failed.",
    "errors": [
      {
        "message": "Precondition check failed.",
        "domain": "global",
        "reason": "failedPrecondition"
      }
    ],
    "status": "FAILED_PRECONDITION"
  }
}

(Sleeping for 1 second worked for me; I also tried 0.1 and 0.5 which weren't long enough)

This means it's likely to take some time to send all the drafts, so it would also be nice to display a progress bar. Creating the drafts also seems relatively slow, so a progress bar would help there.