# Working with email

## &#x20;For sending email messages&#x20;

{% hint style="warning" %}
Please note!

When executing functions for working with email messages, the function returns:

a) either <mark style="color:green;">**NONE**</mark> — upon successful execution of the function;

b) or <mark style="color:red;">**an error status**</mark> text.
{% endhint %}

send\_email() | send\_email\_from\_bot() | send\_email\_template()

<details>

<summary>Description</summary>

<mark style="background-color:blue;">**For sending an email message**</mark>

**send\_email(to\_email, subject, message)**&#x20;

Parameters:

<mark style="color:red;">**!**</mark>**&#x20;to\_email - recepient's** email address

<mark style="color:red;">**!**</mark>**&#x20;subject -** email subject

<mark style="color:red;">**!**</mark>**&#x20;message -** email body text

<mark style="background-color:blue;">**For sending email messages via the bot**</mark>

**send\_email\_from\_bot(email\_bot, client\_email, email\_subject, text, attachment\_url)**&#x20;

Parameters:

<mark style="color:red;">**!**</mark>**&#x20;email\_bot** - email address linked to email distribution channel \ <mark style="color:red;">**!**</mark>**&#x20;client\_email** - client’s email address where a message will be sent\ <mark style="color:red;">**!**</mark>**&#x20;email\_subject** - email subject (title)\ <mark style="color:red;">**!**</mark>**&#x20;text** - message body sent in email \
**attachment\_url** - attachment URL&#x20;

<mark style="background-color:blue;">**For forwarding a draft or sent email**</mark>

**send\_email\_template(mailing\_id, client\_email, email\_bot, date)**

Parameters:

<mark style="color:red;">**!**</mark>**&#x20;mailing\_id** - mailing template ID (either a draft or a ready email)

<mark style="color:red;">**!**</mark>**&#x20;client\_email** - recepient's email address

**email\_bot** - sender's email address; by default, email connected to project

**date** - email sending date in format ‘dd.mm.yyyy HH:mm’.  If a date is in the past or omitted, email will be sent immediately after the function call.

</details>

<details>

<summary>Example</summary>

For sending an email message:

<div data-with-frame="true"><figure><img src="/files/5fxo9Tek1jdFem9SO2H4" alt=""><figcaption></figcaption></figure></div>

Sending via the bot

<div data-with-frame="true"><figure><img src="/files/RIppAobYayb1HELixFYl" alt=""><figcaption></figcaption></figure></div>

Example of sending a previously sent email:

We take the variable from the mailing list - id.

In this example, it’s 483, which will be used as the mailing\_id.

We go to the constructor and call the function with the following parameters:

Option 1 – specifying parameters explicitly:

`e_letter = send_email_template('483', "test@mail.ru", '', '09.08.2022 15:00')`

Option 2 – specifying parameters using variables:

`mailing_id = '483'`\
`client_email = 'test@mail.ru' # recipient email`\
`email_bot = ''`\
`date = '09.08.2022 15:00' # since the date is already past at the time of sending, the email will be sent immediately upon function call`\
`e_letter = send_email_template(mailing_id, client_email, email_bot, date)`

<div data-with-frame="true"><figure><img src="/files/w82OAE93z2BvBo27PDaF" alt=""><figcaption><p>Example setting for sending an email</p></figcaption></figure></div>

As a result, when the function was called, the template of the pre-prepared email was sent to <test@mail.com>.

</details>

<details>

<summary>Code example for copying</summary>

```
send_email('john.smith@gmail.com', 'This is a title', 'And this is a text')

/*via the bot*/
mailing = send_email_from_bot('test_channel@test.com', 'test_client@gmail.com', 'Email subject. Just simple', 'Hi, I'm sending you my message', 'https://sun9-82.userapi.com/impg/L3ZYWHnlseIQsqZO')
```

</details>

## For confirming mailings to the client’s email address

confirm\_email\_subscription()

<details>

<summary>Description</summary>

**confirm\_email\_subscription(email, sender\_name, bot\_email, callback,client\_name)**

{% hint style="info" %}
This function is designed to collect consent from clients for sending email campaigns.

When a client provides their email address via messenger, a consent request is sent first.&#x20;An email client is created only after the client confirms their consent.

As a result, email addresses with confirmed consent are considered more trustworthy, which helps improve your overall email deliverability and sender reputation.
{% endhint %}

{% hint style="warning" %}
Important!&#x20;

You cannot send mailings containing potentially promotional content without the client’s consent.

Do not disregard this information to avoid penalties for violations.
{% endhint %}

Parameters:

**email** - client’s email address for verification and addition

**sender\_name** - company name from which you request consent to receive newsletters

**bot\_email** - bot email address to which a new email client will be linked

**callback** - callbacks are (or are not) required for clients who confirm their email address and for a new email client (default: False)

**client\_name** - name that will be assigned to a email client

Sent callbacks will have the following format:

"client\_accept\_email\_subscription: #{email}" - callback to a client confirming his email address

"email\_client\_accepted\_by ID:#{@client.id}" - callback to a new client (the confirming client’s ID will be stored in the variable client\_father\_id)

Send a message to verify the address after the user provides his email.

After the user confirms his consent to receive newsletters from the company, a new email client will be added to your list.

This way, you won’t have any "dead leads" in your campaigns, and your email database will consist only of addresses from clients genuinely interested in your products.

</details>


---

# 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/chatbot/functions/calculator/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.
