# Cómo usar Google Sheets para envíos

* [Cómo configurar una hoja](#how-to-set-up-the-sheet)
* [Cómo activar un script](#how-to-activate-the-script)
* [Cómo configurar el chatbot](#how-to-configure-the-chat-bot)
* [Cómo configurar un disparador](#how-to-set-up-a-trigger)

## Cómo crear envíos con la ayuda de Google Sheets

Cómo funciona: el bot recopila nuevas direcciones y las pega una por una en la primera columna (A3:A en la hoja "Sending"). El script de Google se inicia cuando se establece la hora o cuando cambias la hoja (dependiendo de cuál sea el disparador), crea un envío con nuevas direcciones y las mueve a la hoja "Log" con una marca de tiempo.

```
function SendMail() {

var ss = SpreadsheetApp.getActiveSpreadsheet()
var sheet = ss.getSheetByName("Sending")
var email = sheet.getRange("a3:a").getValues()
var subj = sheet.getRange("c2").getValue()
var body = sheet.getRange("d2").getValue()
var arr = []

MailApp.sendEmail(email, subj, body)
arr = [[new Date(), email]]

//escribir las direcciones enviadas en Log
ss.getSheetByName("Log").getRange(ss.getSheetByName("Log").getLastRow()+1, 1, 1, 2).setValues(arr)
//limpiar la hoja Sending
sheet.getRange("a3:a").clearContent()
}
```

La configuración consta de 4 partes: **configuración de la hoja, activación del script, configuración del chatbot** y **configuración de un disparador**

## Cómo configurar una hoja

Crea una copia de [la hoja con el código](https://docs.google.com/spreadsheets/d/1SJYyF1YRJ-BWflqy_8Ad9zvbJCO1Tv7nIItiBadmeIc/edit?usp=sharing): Archivo -> Hacer una copia

![](https://lh4.googleusercontent.com/0znfipVFnBgjF0xaHim-CaAE2jpFerBN07E_eWb7w_6qg0-HKaL91a1GartyWuiNL-5IdyXEZ6eP9_hptfzLdas86wEnknas5lYRM155hbFBZvRjVMmhq3TPWH00hqNGpfTDHWTReIEVd9Y7JA)

Fíjate en que dice que los scripts también se copiarán: asegúrate de que se copien al duplicar la hoja. Pulsa "Hacer una copia".

![](https://lh6.googleusercontent.com/WmeNROF_YPBTaR5YQ7pUu_YRO6sJ7VmZ9JUS3oOmpdDVDqFYJNV2sGPcSG8Vtya6jBe6ul9xTHU7z1YM0mK7PiKUMVrj4UqMpF7KmiDivpVEGAB1Q_Fsrq0UNap_sn30WUvt8eEJto-qEKFSMQ)

En la hoja "Sending" solo cambias las columnas B2 y C2:

![Sobre la hoja: el bot pega las direcciones en la primera columna (A3:A en la hoja "Sending"). Solo tienes que cambiar las columnas del asunto y del mensaje, nada más](https://lh3.googleusercontent.com/dL8NVFfqvpbXApcPNBN98na1DpwkRt5h30uPtLspmvGgSHenjO3GWyLjV1TYjyXrlcb0qkBeNDNu5qJVZP4kBko_o9bVZW9hHpyd93ZSkGGP1lHAQCkN4xTn1SivbYo0ILKCdSdll_OA98sdMQ)

Ahora debes comprobar el acceso a tu hoja; tiene que estar disponible para editar por cualquier persona con el enlace, como en la captura de pantalla de abajo.

![](https://lh4.googleusercontent.com/hUpiJdh33M7hKw-DG1jLic1N9vl6HSBnHet6TMKbATLsZG-CraY7-oI3hNKLKsCmlXXhP9QCfu5TdlN1F_odYBy1N0Eki9jebxEtPVowSBLMm61Ci2E5by80nQVg7dhrYWxV4Max2vCyvk9tcQ)

## Cómo activar el script

En tus hojas, Extensiones -> Apps Script

![](https://lh4.googleusercontent.com/EQxeAihqUiXpWkR06psB0UY2ZqYGpkJ_Djk1GBlg9ASWZZ22m4QL48OBGiu8mBG7Y3SAruChb8xqzUjL2F2uWsEocOc0N5VEB9jgXdN39E8nKWpwIkBqFjk73iy1U7T5MWprgykr94wa9wHVtA)

Elige **"SendMail"**

![](https://lh3.googleusercontent.com/CznVVRkKKT4vG95VASXmWbFrnnptM91Bkaz_8oTcQ6i6mBJ7o8zaQOnKjtDo5r-DuCcoAsB24cA7wWz0TpkOzcXrLBIcWQlgk0Q8QJwOmtvW7OcyXjlB1klYsat4PG12j9UuhjB2Kc_3wkDi6Q)

Pulsa **"Ejecutar"**

![](/files/b8057aac7d6ff07238f3ab73e21b656ad8a3b56f)

Pulsa **"Revisar permisos"**

![](https://lh5.googleusercontent.com/mkuOfM_1Q2ZOhrZV-y3wvdjSmiMIIVvG08hv15N9iWb5UkqKFUgOpvYFKFTNJdhn-6do7DyFTPDqwr4Zw9GlxvgaOdQp8ehiRCZKgumr9sDmhJsN-uD_saMsawV88YVm3fwe5nDEFvSdzVqxoQ)

Elige la cuenta desde la que quieres enviar el mailing.

![](https://lh4.googleusercontent.com/WMnh64nzsoFhNHlbTEOYeniFcXMd4UKOauXFxmTgOb_t4vHzyC_fb6bOl_WNxDRsDgYA9sggerakcy1_6SIZ_fG0PbKER8-cDR3swEngIaTcFD3aIfFVc-tkHUrl_qKHUVnWp7ooIiiNxjngLw)

Pulsa **"Avanzado"**

![](https://lh6.googleusercontent.com/KKVlceduQy1mvcFBb_Fzdkb9dAVCG4oBcxBkdSfBPV92_zkZGKn6sVpZfbrHVC8EQo3U_-7I1dGpkUzgYRCTrxvfg5Uu61ZJgcSVaEd5GJf2DSEEE2WMZmbB4l-ILT_ncPqeOvGbNlP-LQXcrA)

Pulsa **"Ir a (el nombre del script) (no seguro)"**

![](https://lh3.googleusercontent.com/d0h-SyYP_emJpadCb4je04Md04JCj4W7Y6Nnk34LpFY96Vu_G_E6aJ8rhq1N-fJAdu0fYgisCgJLAuvD-ZwSaL5NlC_9k0Sasq5OWLMWyohx2Fok2oJFSy278l-9iDVPL8aHpMj6uu2S388F8A)

Pulsa **"Permitir"**

![](https://lh3.googleusercontent.com/ed24LwyVea_PNw09wUZNFWwC8Vlu7jt96z3hajRQz-rBR63Hjws473KrFhppSEMXdFJTHJ5dCfbz_UPl0lmdnZgiujvgOtDTgAGfNk9ajglJhTy8MvCJU71DGCo1TnlfkN_IPs7_kjLI2XswSA)

Ahora debes asegurarte de que el script se haya activado comprobando el correo de alerta de seguridad en tu cuenta

![](https://lh6.googleusercontent.com/CA0T1ucBr43qZm2mGtnNKXhQB7r6aAlLLD6dqZ60ADBGrH9ewKIENTx96ohZfPYlfL2rxSA9wOa_3off0NnimW3yUSiNVt34s1ko9TYfPEWhLxZBo-2GCYTo8ZfSrEikHbpkfkoQHMEeKfFPDA)

## Cómo configurar el chatbot

Tomemos como ejemplo el siguiente esquema que consta de tres bloques

![](https://lh3.googleusercontent.com/CZWqjtQ4jFIV44IYZGjF4K6HGaEBN2cdBFYGr1PbwoW-7_hq37l51n4aHFkH3pUZyAM5rrN9DoMxkZPxG26VYNqgGdmBmF9EChesJXIfcWtffqHskemFU5-kakeJcwzERMxxMsgVfFCIUrEx7A)

1\) El primer bloque verde **"Comprobación de condición principal"** está iniciando el diálogo con el bot. Aquí escribimos en las condiciones la frase que lo iniciará. Para asegurarte de que los ajustes se guardan en los bloques, no olvides pulsar **"Guardar"** después de añadir.

![](https://lh6.googleusercontent.com/6ffv52weuudLlHsC1AXgyl48u4QXdyxSv2O0K6sfxPVBrOlYJkGVbsqQ6hGNRsk4VjNGWZn9dtdCPjOWXKbujTm8iR_N-JL1L8hO4WKfixQ_FAY3eiN6m0H_5WCN-Adc5OwJ0G8UtfimAPbbgg)

2\) Ahora crea un bloque debajo y edita la conexión. Abre la pestaña "El usuario introduce datos" y pega el nombre de la variable (client\_mail, como en el ejemplo). Luego coloca una expresión regular en la condición para verificar el correo electrónico. En este punto, es importante comprobar la exactitud de los datos insertados; de lo contrario, el script se bloqueará mucho. Puedes usar cualquiera de las siguientes expresiones:

^\[a-z0-9]\[a-z0-9\_.-]*@(\[a-z0-9]+.)*\[a-z0-9]\[a-z0-9-]+.(\[a-z]{2,6})$

^\[-\w.]+@(\[A-z0-9]\[-A-z0-9]+.)+\[A-z]{2,4}$

![](https://lh6.googleusercontent.com/50dUCHfRgUdqhue-PmZ5nCi5ndIWEnZdCOZijnq6e26HtTVcgzQRzLSoYsVOJ0CMKDmuYLWEpbA5J29GDD4oO4xJsQoC9brKIpv7j-udJ3qsX335tMrFjsLvRIbW9c99Rwc14GaIM0gTBeE_kw)

Más sobre expresiones regulares [aquí](https://docs.salebot.ai/variables/list-of-useful-regular-expressions)

3\) El siguiente bloque es el que transfiere los datos a la hoja. Configura todo tal como aparece en la captura de pantalla (la descripción de los campos está abajo)

![](https://lh5.googleusercontent.com/zkwBa6IAlb8tbGQsyYyancfz-svS1jEZ_5IqOoW4hMqaupiEgFP7QboWH8t6C5a-efwgxdhOhMhi62LAG0leRyUsWBxFEOF5MVmouhAyPpxBTw7GH1ncpAjiz_tI7HMH834EAZvAD9UpPH55LA)

* Elige el tipo de solicitud POST-json.
* Pega la URL de la función en la pestaña “URL request”.

  \_<https://store.salebot.ai/function/gsheets_&#x20>;
* Pega la siguiente línea en la pestaña “JSON parameters” \
  \
  \&#xNAN;*{"id": "(your id parameter)", "mapping":{"a":"#{client\_mail}"}, "list\_name": "Sending"}*\
  \
  Pega tu parámetro id desde el enlace a tu hoja. Puedes encontrarlo en el enlace, después de d/

![](https://lh5.googleusercontent.com/o6lwAhIQht-QCEaMmgKJigcS_YGkWcQ3lnyBL7ny0NTgcl160dBbwsu6lFuhjntkKxzElimLGXll5vhEv5ZlzqkQJ75A-TM9p_8Tr8cNVUCRTwQbp6f5UURrvAmzsxxrrJ3JkYDTfk0M100vjg)

## Cómo configurar un disparador

Antes de crear un disparador, comprueba que el bot escribe los datos en la hoja y que la función funciona correctamente.

![](https://lh5.googleusercontent.com/of8l8zMhl_K_0TQu016FdRxrpqiynd7rSYtvDbURmpZw3Nl8fxA5tAdenyG-r1bNVHW7kZmZCnCwNin3-auJpSPKQIa6WvdPqmbQNsR0GzEmbHEGM18ZIGkscbggkkDVbnKH07NsuTrVF_wp-w)

Si todo salió bien, abre Extensiones -> Apps Script -> SendMail y luego Triggers en el menú de la izquierda.

![](https://lh4.googleusercontent.com/C8vlOIX_davRzXgp6aqzkwnmNSIutirJSrajGNdyg2fDtTVZrk2s6l3KUBgo3DX_AgMKCCS1DQixPM6Wt72aGF6Pr2ExuUfGE1m76-nQj0J1dOUOk8_xnCNpKGpN8aoz1EAjyD1c87WuCqQNrQ)

Crea un nuevo disparador usando el botón en la esquina inferior derecha de la pantalla

![](https://lh6.googleusercontent.com/rZBUefTUe_7NH70qsa9xEW_jbYf0IAGMvUcstUzHEoaZSUTzr041wisei6UNxCxFB1y938qHjg2gBnFGEdqB1_OLvarMltZQbYZxKw1LJuEE-BzDElQ1PtBjYOSjofG-QE8Ml6G2QDz77mKjSA)

Configúralo como en la captura de pantalla. Si lo estás configurando como basado en tiempo, ten en cuenta que el intervalo debe ser de al menos 30 minutos. Puedes elegir tus propios valores, pero recuerda que hay ciertos [cuotas](https://developers.google.com/apps-script/guides/services/quotas). Luego pulsa **"Guardar"**.

![](https://lh5.googleusercontent.com/K6zGZeA95Cxg0ylq4ZpwOjBGwovnvpAIHbxutgTT0pwosoQD2e69VhvM87O-qVwykxjIPCslC4Ht2eFSdl2ecAg4WTJ1CqKCEGNBnlf9vPqGtG3tncEyguFmv1WYn7zWhTV5iynnNdzibw6zLA)

Ahora hay un disparador en la lista. ¡La configuración está completa!

![](https://lh6.googleusercontent.com/jyjPMqqLvPL0yUZcvNFWexSmaCXJ91JyWykbMylzqitwEBKNtmU2SUo0gU4SQwd5unJLAcuphVMvD61IVR79lFhOdULbuNsaJwOgxkMRVq45RmVitPSr70YAw2HNqebe6IalO1mbey4ebZN1ng)

#### Otros enlaces útiles:

[Límites de envío de Gmail en Google Workspace](https://support.google.com/a/answer/166852?hl=en)

[Más información sobre el servicio Gmail](https://developers.google.com/apps-script/reference/gmail/)

[Cuotas para Google Services](https://developers.google.com/apps-script/guides/services/quotas)


---

# 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://docs.mavibot.ai/doc/es/funciones-especiales/como-usar-google-sheets-para-envios.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.
