bigfunctions > send_mail_with_sendgrid
send_mail_with_sendgrid¶
Call or Deploy send_mail_with_sendgrid
?
✅ You can call this send_mail_with_sendgrid
bigfunction directly from your Google Cloud Project (no install required).
- This
send_mail_with_sendgrid
function is deployed inbigfunctions
GCP project in 39 datasets for all of the 39 BigQuery regions. You need to use the dataset in the same region as your datasets (otherwise you may have a function not found error). - Function is public, so it can be called by anyone. Just copy / paste examples below in your BigQuery console. It just works!
- You may prefer to deploy the BigFunction in your own project if you want to build and manage your own catalog of functions. This is particularly useful if you want to create private functions (for example calling your internal APIs). Discover the framework
Public BigFunctions Datasets:
Region | Dataset |
---|---|
eu |
bigfunctions.eu |
us |
bigfunctions.us |
europe-west1 |
bigfunctions.europe_west1 |
asia-east1 |
bigfunctions.asia_east1 |
... | ... |
Description¶
Signature
send_mail_with_sendgrid(gmail_email, gmail_app_password, to, subject, content, attachments)
Description
Sends an email using your gmail account
Param | Possible values |
---|---|
gmail_email |
The email for your gmail account |
gmail_app_password |
An App Password of your gmail account. 1.Get an App Password. ⚠️ 2. Encrypt the password wit the button below before copying it to your queries! |
to |
One or multiple comma separated emails. For instance contact@unytics.io or contact@unytics.io, paul.marcombes@unytics.io |
subject |
Email subject |
content |
Email content |
attachments |
json like {filename: content} with content a plain text or base64 encoded bytes (for excel, pdf, image, etc) |
⚠️ Encrypt your secrets!
Do NOT write secrets in plain text in your SQL queries!
Otherwise, anyone with access to your BigQuery logs can read them.
Instead, generate an encrypted version of your secret that you can safely share.
Enter a secret value to encrypt below along with the emails of the users who are authorized to use it. It will generate an encrypted version that you can paste into the arguments of your function (exactly like if you passed the plain text version). If a user, who is not in the auhorized users list, tries to use the encrypted version, the function will raise a permission error. Besides, the encrypted version can only be used with this function
send_mail_with_sendgrid
.
Encrypt a secret
How secret encryption works
Technically, this encryption system uses the same encryption mechanism used to transfer data over the internet. It uses a pair of a public and private keys.
The public key (contained in this web page) is used to encrypt a text. The corresponding private key is the only one who is able to decrypt the text. The private key is stored in a secret manager and is only accessible to this function. Thus, this function (and this function only) can decrypt it.
Moreover, the function will check that the caller of the function belong to the kist of authorized users
that you gave at encryption time.
Thanks to this:
- Nobody but this function will be able to decrypt it.
- Nobody but
authorized users
can use the encrypted version in a function. - No function but the function
send_mail_with_sendgrid
can decrypt it.
Examples¶
1. Send email without file attached
select bigfunctions.eu.send_mail_with_sendgrid('paul.marcombes@unytics.io', 'ENCRYPTED_SECRET(kdoekdswlxzapdldpzlfpfd...)', 'you@example.com', 'I love BigFunctions', 'Hey Paul, could you deploy more BigFunctions 🙏?', null)
select bigfunctions.us.send_mail_with_sendgrid('paul.marcombes@unytics.io', 'ENCRYPTED_SECRET(kdoekdswlxzapdldpzlfpfd...)', 'you@example.com', 'I love BigFunctions', 'Hey Paul, could you deploy more BigFunctions 🙏?', null)
select bigfunctions.europe_west1.send_mail_with_sendgrid('paul.marcombes@unytics.io', 'ENCRYPTED_SECRET(kdoekdswlxzapdldpzlfpfd...)', 'you@example.com', 'I love BigFunctions', 'Hey Paul, could you deploy more BigFunctions 🙏?', null)
+---------+
| success |
+---------+
| true |
+---------+
2. Send email with plain text file attached
select bigfunctions.eu.send_mail_with_sendgrid('paul.marcombes@unytics.io', 'ENCRYPTED_SECRET(kdoekdswlxzapdldpzlfpfd...)', 'you@example.com', 'I love BigFunctions', 'Hey Paul, could you deploy more BigFunctions 🙏?', json_object('report.csv', 'col1,col2\nval1,val2\nval3,val4'))
select bigfunctions.us.send_mail_with_sendgrid('paul.marcombes@unytics.io', 'ENCRYPTED_SECRET(kdoekdswlxzapdldpzlfpfd...)', 'you@example.com', 'I love BigFunctions', 'Hey Paul, could you deploy more BigFunctions 🙏?', json_object('report.csv', 'col1,col2\nval1,val2\nval3,val4'))
select bigfunctions.europe_west1.send_mail_with_sendgrid('paul.marcombes@unytics.io', 'ENCRYPTED_SECRET(kdoekdswlxzapdldpzlfpfd...)', 'you@example.com', 'I love BigFunctions', 'Hey Paul, could you deploy more BigFunctions 🙏?', json_object('report.csv', 'col1,col2\nval1,val2\nval3,val4'))
+---------+
| success |
+---------+
| true |
+---------+
3. Send email with excel file attached
select bigfunctions.eu.send_mail_with_sendgrid('paul.marcombes@unytics.io', 'ENCRYPTED_SECRET(kdoekdswlxzapdldpzlfpfd...)', 'you@example.com', 'I love BigFunctions', 'Hey Paul, could you deploy more BigFunctions 🙏?', json_object(
'report.xlsx',
(select bigfunctions.eu.json2excel(json '[{"col1": "val1", "col2": "val2"}, {"col1": "val3", "col2": "val4"}]'))
)
)
select bigfunctions.us.send_mail_with_sendgrid('paul.marcombes@unytics.io', 'ENCRYPTED_SECRET(kdoekdswlxzapdldpzlfpfd...)', 'you@example.com', 'I love BigFunctions', 'Hey Paul, could you deploy more BigFunctions 🙏?', json_object(
'report.xlsx',
(select bigfunctions.us.json2excel(json '[{"col1": "val1", "col2": "val2"}, {"col1": "val3", "col2": "val4"}]'))
)
)
select bigfunctions.europe_west1.send_mail_with_sendgrid('paul.marcombes@unytics.io', 'ENCRYPTED_SECRET(kdoekdswlxzapdldpzlfpfd...)', 'you@example.com', 'I love BigFunctions', 'Hey Paul, could you deploy more BigFunctions 🙏?', json_object(
'report.xlsx',
(select bigfunctions.europe_west1.json2excel(json '[{"col1": "val1", "col2": "val2"}, {"col1": "val3", "col2": "val4"}]'))
)
)
+---------+
| success |
+---------+
| true |
+---------+
Need help using send_mail_with_sendgrid
?
The community can help! Engage the conversation on Slack
For professional suppport, don't hesitate to chat with us.
Found a bug using send_mail_with_sendgrid
?
If the function does not work as expected, please
- report a bug so that it can be improved.
- or open the discussion with the community on Slack.
For professional suppport, don't hesitate to chat with us.
Spread the word¶
BigFunctions is fully open-source. Help make it a success by spreading the word!