Movatterモバイル変換


[0]ホーム

URL:


Skip to contentSkip to navigationSkip to topbar
Go to the Twilio Docs home page
Twilio Docs

Send email with Twilio SendGrid


The CLI features a built-in integration with Twilio SendGrid, allowing you to send emails directly from your terminal.


The first prerequisite to send an email with the Twilio CLI is to have aSendGrid API Key(link takes you to an external page) set as theSENDGRID_API_KEY environment variable.

Create and copy a new SendGrid API Key, or copy an existing one, then run:

exportSENDGRID_API_KEY=the_key_you_copied_from_SendGrid
(warning)

Warning

Remember, emails will fail to send if you have not defined yourSENDGRID_API_KEY environment variable. Refer to theprevious directions to do so.


Runtwilio email:set to set defaults for the sender's email address and subject line.

1
$twilio email:set
2
?Default email address of the sender: your.email@example.com
3
?Default subject lineforall emails: Ahoy, there!
4
Defaultsending email address has been set to: your.email@example.com
5
Defaultsubject line has been set to: Ahoy, there!
6
twilio-cliconfiguration saved to "/Users/example/.twilio-cli/config.json"

After you set these defaults,twilio email:send will automatically apply them to any sent emails.


To send emails with an interactive prompt, run:

twilioemail:send

You will be prompted for details such as the recipient's email address, email text, and if you want to provide an attachment.

If you'd like to skip the prompt, provide details as flags instead:

1
twilioemail:send\
2
--to="me@example.com"\
3
--text="Look at this fluff: https://unsplash.com/photos/uhnZZUaTIOs"

To change the sending email address or subject line, you can either re-runtwilio email:set, or use the corresponding flag to set a new value for the item you want to change in that specific command.

For example, to override the default subject:

1
twilioemail:send\
2
--to="me@example.com"\
3
--subject="That cat pic you wanted"\
4
--text="Look at this fluff: https://unsplash.com/photos/uhnZZUaTIOs"

To send an email with an attachment, runtwilio email:send and wait to be prompted to add an attachment.You can also use--attachment=filePath to attach a file:

1
twilioemail:send\
2
--attachment=/Users/example/Downloads/cutest-kitteh.png
(warning)

Warning

You may run into permission issues when the CLI tries to read your file. If so, usesudo with the-E flag to preserve your SendGrid key:

1
sudo-Etwilio email:send\
2
--attachment=/Users/example/Downloads/cutest-kitteh.png

Send command output as an attachment

send-command-output-as-an-attachment page anchor

To send the output of a different command as an email attachment, pipe that command totwilio email:send.

1
psau\
2
|twilioemail:send\
3
--to="me@example.com"\
4
--text="See attachment"

If a default sending email address and subject line has been set, the command will automatically use the defaults, and you only need to include values for--text and--to.

If there is not a default subject line and sender's email address, all flags need to be included to send the output of the piped command.

1
psau\
2
|twilioemail:send\
3
--from="me@example.com"\
4
--to="me@example.com"\
5
--subject="Current processes"\
6
--text="See attachment"

[8]ページ先頭

©2009-2025 Movatter.jp