# Send your data by email using gmail API

When a script has finished running, you may want to email the results by using the Gmail API.\
\
you must first install and load the package gmailr package.

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

```

if you are going to display some kind of table I would suggest to also install the tableHTML package.

```r
install.packages("tableHTML")
library(tableHTML)
```

```
#
 
# Packages loading


# 
```

The Next step is to connect to Gmail API. You need to activate it in your Google Cloud project [More info here ](https://gargle.r-lib.org/articles/get-api-credentials.html)and then replace the fake value with your key and secret in the following example. &#x20;

```r
gm_auth_configure("mykey.apps.googleusercontent.com", "mysecret") 
```

This commande will transform your dataframe into an html table

```r

#transform the data frame 'df' to a html table
msg = tableHTML(df)
 
# Construct email
# end send it

```

we build the email

```
test_email <- gm_mime() %>%
              gm_to("another@example.com") %>%
              gm_from("me@example.com") %>%
              gm_subject("Email title") %>%
              gm_html_body(paste("Hi Mate,<br />
Here are the data you requested:<code>", msg,"<br /><br />Kind regards,<br />Me"))

```

and we send it

```
gm_send_message(test_email)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.rforseo.com/export-data/send-your-data-by-email.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
