Automate Your Email Notifications with Rust and Discord Webhooks
In this tutorial, you’ll learn how to create a simple yet powerful email-to-Discord notification system using RustMailer. With a few steps, you can monitor an email inbox and forward new mail events directly to a Discord channel via webhooks.
Step 1: Create an Email Account
Use RustMailer’s Web UI or API to create a new email account. Once created, you'll receive an Account ID.
See how to register a gmail account
Step 2: Create a Discord Webhook
Head over to your Discord server, choose a channel, and create a Webhook URL.
Discord only requires the URL; no headers or auth tokens are needed for basic usage.
Step 3: Add a Webhook in RustMailer
- Event Type:
EmailAddedToFolder
- Method:
POST
- Target URL: your Discord webhook URL
Next, use a VRL (Vector Remap Language) script to transform the raw email event into a structured payload compatible with Discord's embed format. This allows your Discord channel to receive well-formatted notifications with fields like sender, subject, date, and even attachments.
if .event_type == "EmailAddedToFolder" {
# Create a new object to store filtered and transformed data
my_payload = {}
my_payload.username = "RustMailer"
my_payload.avatar_url = "https://github.com/rustmailer.png"
embed = {}
embed.title = "New Email Notification"
embeddescription, err = "you've got a new email in " + .payload.account_email
embed.description = embeddescription
embed.color = 16711680
embed.fields = [
{
"name": "Sender",
"value": .payload.from.address
},
{
"name": "subject",
"value": .payload.subject
},
{
"name": "mailbox",
"value": .payload.mailbox_name
},
{
"name": "date",
"value": format_timestamp!(from_unix_timestamp!(.payload.date, unit:"milliseconds"), format:"%Y-%m-%d %H:%M:%S")
}
]
embed.footer = {
"text": "RustMailer New Email Notification",
"icon_url": "https://github.com/rustmailer.png"
}
embed.timestamp = now()
my_payload.embeds = [embed]
for_each(array!(.payload.attachments)) -> |_index, attachment| {
title, err = "Attachment: " + attachment.filename
description, err = "Type: " + attachment.file_type
embed_i = {
"title": title,
"description": description
}
my_payload.embeds = push(my_payload.embeds, embed_i)
}
if .payload.message.plain.content != null {
my_payload.content = .payload.message.plain.content
} else if .payload.message.html != null {
my_payload.content = .payload.message.html
}
# Replace the original event with the filtered payload
. = my_payload
} else {
# For all other event types, discard the event by setting output to null
. = null
}
Click Save in the UI.
Step 4: Send a Test Email
Trigger an actual email to test the pipeline.
Send a POST
request to RustMailer’s send mail API:
POST http://localhost:15630/api/v1/send-mail/645769057535377
Payload:
{
"from": {
"address": "rustmailer.git@gmail.com"
},
"recipients": [
{
"to": [
{
"address": "rustmailer.git@gmail.com"
}
]
}
],
"subject": "Product Inquiry: RustMailer Enterprise Use and Licensing",
"text": "Hi RustMailer Team,\n\nI'm reaching out to learn more about RustMailer and its suitability for one of our upcoming projects. We are building a secure self-hosted mail gateway for internal use, and RustMailer seems like a promising fit.\n\nCould you please help clarify the following:\n\n1. What are the licensing requirements for commercial use?\n2. Do you offer any enterprise support plans or SLAs?\n3. Can RustMailer handle approximately 150k+ emails/day across 500+ mailboxes?\n4. Are there any Docker deployment best practices or system requirements you recommend?\n\nWe’d also be happy to explore a paid license or support contract if it aligns with our needs.\n\nLooking forward to your response.\n\nBest regards,\n\nJason Lee\nSenior DevOps Engineer \nTechFlow Solutions\njason.lee@techflow.io",
"send_control": {
"dry_run": false
}
}
RustMailer supports advanced delivery controls via the send_control
field. You can use it to enable features like delayed sending, retry strategies, and click/open tracking.
In this example, we're sending the email immediately and leaving other controls at default.
Step 5: Verify the Results
After sending, check the following:
-
Mail Queue shows the sent email
-
Webhook Queue shows the triggered event
-
Inbox receives the test email
-
Discord displays the email alert
RustMailer offers true WYSIWYG integration—every action you perform in the UI is backed by corresponding OpenAPI and gRPC interfaces. This makes it easy to embed RustMailer’s powerful email capabilities directly into your own applications or services.