Working with email

For sending email messages

send_email() | send_email_from_bot() | send_email_template()

Description

For sending an email message

send_email(to_email, subject, message)

Parameters:

! to_email - recepient's email address

! subject - email subject

! message - email body text

For sending email messages via the bot

send_email_from_bot(email_bot, client_email, email_subject, text, attachment_url)

Parameters:

! email_bot - email address linked to email distribution channel ! client_email - client’s email address where a message will be sent ! email_subject - email subject (title) ! text - message body sent in email attachment_url - attachment URL

For forwarding a draft or sent email

send_email_template(mailing_id, client_email, email_bot, date)

Parameters:

! mailing_id - mailing template ID (either a draft or a ready email)

! 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.

Example

For sending an email message:

Sending via the bot

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', "[email protected]", '', '09.08.2022 15:00')

Option 2 – specifying parameters using variables:

mailing_id = '483' client_email = '[email protected]' # 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)

Example setting for sending an email

As a result, when the function was called, the template of the pre-prepared email was sent to [email protected].

Code example for copying
send_email('[email protected]', 'This is a title', 'And this is a text')

/*via the bot*/
mailing = send_email_from_bot('[email protected]', '[email protected]', 'Email subject. Just simple', 'Hi, I'm sending you my message', 'https://sun9-82.userapi.com/impg/L3ZYWHnlseIQsqZO')

For confirming mailings to the client’s email address

confirm_email_subscription()

Description

confirm_email_subscription(email, sender_name, bot_email, callback,client_name)

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. 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.

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.

Last updated