React & Next.js email
Send your first Venmail test email from Node.js
Use a small server-side script to verify credentials and a sender before connecting a React app.
Test the sending connection outside your app first. A short Node.js script makes it easier to identify an endpoint, credential or sender problem before adding forms, templates and queues. Send only to a mailbox you control for this first check.
The example uses the documented structured-message interface with X-Server-API-Key. Copy the full send endpoint and authorized sender from the documentation for your provisioned account. A mailbox login, partner API token and server API key are not interchangeable.
Prepare the test
- 1
Set server-only environment values
Provide VENMAIL_SEND_URL, VENMAIL_SERVER_KEY, VENMAIL_FROM and VENMAIL_TEST_TO through your local secret configuration. Keep the key out of source control and shell screenshots. Use the documented HTTPS send endpoint, not a URL from a form input.
- 2
Save the script
Save the code below as send-test.mjs and run it with a supported Node.js version that provides fetch. The script sends one plain-text message and prints only the response status, not the credential.
- 3
Read both results
Check the script's API status and the destination mailbox. If the API rejects the request, investigate that response in a secure local debugger. If accepted, inspect delivery separately before declaring success.
- 4
Keep it out of the client
When the test works, move this operation behind your application's server boundary. Add persistence and controlled retry behavior before making it part of a customer-facing flow.
send-test.mjs — one controlled send
const names = ["VENMAIL_SEND_URL", "VENMAIL_SERVER_KEY", "VENMAIL_FROM", "VENMAIL_TEST_TO"];
for (const name of names) {
if (!process.env[name]) throw new Error("Missing " + name);
}
const endpoint = new URL(process.env.VENMAIL_SEND_URL);
if (endpoint.protocol !== "https:") throw new Error("Use the documented HTTPS endpoint");
const response = await fetch(endpoint, {
method: "POST",
headers: {
"X-Server-API-Key": process.env.VENMAIL_SERVER_KEY,
"Content-Type": "application/json",
},
signal: AbortSignal.timeout(15000),
body: JSON.stringify({
to: [process.env.VENMAIL_TEST_TO],
from: process.env.VENMAIL_FROM,
subject: "Controlled Venmail connection test",
plain_body: "This is a test to a mailbox I control.",
}),
});
const result = await response.json();
if (!response.ok || result.status !== "success") {
throw new Error("Send was not accepted; inspect the response securely. HTTP " + response.status);
}
console.log("API accepted the message. Now verify receipt in the test mailbox.");A timeout leaves the outcome uncertain: the service may already have accepted the message. This script deliberately has no automatic retry. Check the sending record before rerunning it, then design application-level deduplication for production.
You can build and test this workflow with free software. For live sending, check API or SMTP access and the sending allowance in your Venmail account; the public Free workspace offer is not a promise of a free production API quota. Venmail, Venmail
Connection verified
- The endpoint matches your account docs
- The key remains server-side
- The sender is authorized
- The intended test inbox received the message
- No timeout was blindly retried
Ready for the next practical step?
Explore Venmail for your email workflow. Check the free features, account limits and integrations that fit your next step.
Explore Venmail's free planRelated practical guides
Send email from a React contact form: the safe pattern
Keep the form in React and put validation, abuse controls and Venmail credentials on the server.
Read the guideBuild a React Email template for Venmail
Render a reusable component to HTML and plain text, then hand it to your server-side sender.
Read the guideSources and review method
Venmail publishes this guide and may be one of the products discussed. We compare providers on consistent dimensions, link to primary documentation and state non-fit cases. Product limits and pricing should be rechecked before purchase.