Using Rust SDK
Learn how to send transactional emails using Plunk with Rust
Plunk’s Rust SDK lets you send transactional emails straight from your Rust application. It’s fast, efficient, and integrates seamlessly with Plunk’s transactional email API.
Setting Up Your Project
First, let’s set up your project with the necessary tools. Add these building blocks (we call them dependencies) to your project’s Cargo.toml
file:
Step 1: Installing Plunk SDK
To start using the Plunk SDK, add it to your project by installing it from Plunk’s Rust SDK on crates.io
Step 2: Setting Up Your API Key
Create a file named .env
in your project’s root directory. This file will securely store your Plunk API key:
💡 Tip: Never share your API key or commit it to version control! Keep it secret, keep it safe.
Step 3: Writing Your First Email Sender
Here’s a complete example broken down into small pieces:
1. Import the tools we need
2. Set up the client
3. Create your email
4. Send the email and handle any results
Understanding the Parts
The Email Structure (PlunkPayloads)
Think of PlunkPayloads
as an envelope for your email. Here’s what each part means:
Part | What It Is | Example |
---|---|---|
to | Who gets the email | "hello@example.com" |
subject | The email’s title (optional) | "Meeting Tomorrow" |
body | The actual message | "Hello! How are you?" |
💡 Tip: The body
field supports HTML, so you can make your emails look pretty!
Sending the Email
When you send an email, two things can happen:
- ✅ Success: The email is sent successfully
- ❌ Error: Something goes wrong (like invalid email address or network issues)
Here’s how to handle both cases:
Common Issues and Solutions
-
Can’t find PLUNK_PRIVATE_KEY
- Make sure you created the
.env
file - Check that your API key is correct
- Make sure the file is in your project’s root directory
- Make sure you created the
-
Email Not Sending
- Check your internet connection
- Verify the recipient’s email address is correct
- Make sure your API key is valid