Socket
Book a DemoInstallSign in
Socket

github.com/starpkg/email

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/starpkg/email

v0.0.0-20250510052426-e35d576c8e48
Source
Go
Version published
Created
Source

📧 email - Starlark Email Module for Resend API

A lightweight Starlark module for sending emails through the Resend API. Seamlessly integrate email capabilities into your Starlark scripts with support for HTML, Markdown, attachments, and comprehensive recipient management.

Overview

The email module provides a simple way to send emails from Starlark with features like:

  • HTML, plain text, and Markdown support
  • File attachments
  • CC/BCC recipients
  • Reply-to configuration
  • Sender domain management
  • Comprehensive response handling
  • Graceful error handling

Installation

go get github.com/starpkg/email

Quick Start

package main

import (
    "github.com/starpkg/email"
    "github.com/1set/starlet"
)

func main() {
    // Create email module with API key and sender domain
    emailModule := email.NewModuleWithConfig(
        "re_123456789", // Resend API key
        "example.com",  // Sender domain for from_id/reply_id
    )

    // Load the module
    loader := emailModule.LoadModule()

    // Run Starlark code with the module
    starlet.Run(`
        load("email", "send")

        # Send an email with HTML content
        result = send(
            subject = "Hello from Starlark!",
            html = "<h1>Hello World</h1><p>This is a test email.</p>",
            to = "recipient@example.com",
            sender = "sender@example.com"
        )

        if result.success:
            print("Email sent successfully!")
            print("Email ID:", result.id)
            print("To:", result.to)
        else:
            print("Failed to send email:", result.error)
    `, loader)
}

Configuration

The email module requires a Resend API key and optionally a sender domain:

  • resend_api_key: Your Resend API key (required)
  • sender_domain: Domain used with from_id and reply_id (optional)

You can configure these values in several ways:

// Method 1: Empty module (configure in Starlark)
module := email.NewModule()

// Method 2: Pre-configured module
module := email.NewModuleWithConfig(
    "re_123456789",  // Resend API key
    "example.com",   // Sender domain
)

// Method 3: With dynamic getters
module := email.NewModuleWithGetter(
    func() string { return getAPIKeyFromVault() },
    func() string { return "example.com" },
)

Usage in Starlark

Basic Email

load("email", "send")

# Simple email with HTML body
result = send(
    subject = "Hello from Starlark!",
    html = "<h1>Welcome!</h1><p>Your account has been created.</p>",
    to = "user@example.com",
    sender = "noreply@example.com"
)

if result.success:
    print("Email sent with ID:", result.id)
else:
    print("Failed to send email:", result.error)

Markdown Content

load("email", "send")

# Email with Markdown content (automatically converted to HTML)
result = send(
    subject = "Meeting Notes",
    markdown = """
    # Team Meeting Notes

    ## Action Items

    - [ ] Update project timeline
    - [ ] Schedule follow-up meeting

    **Note**: Please review by Friday.
    """,
    to = "team@example.com",
    from_id = "meetings"  # Will become meetings@example.com
)

if result.success:
    print("Email sent successfully!")
    print("HTML content:", result.body_html)
    print("Text content:", result.body_text)

Multiple Recipients and Attachments

load("email", "send")

# Email with CC, BCC and attachments
result = send(
    subject = "Quarterly Report",
    text = "Please find the Q3 report attached.",
    to = ["manager@example.com", "director@example.com"],
    cc = "team@example.com",
    bcc = ["records@example.com", "audit@example.com"],
    sender = "reports@example.com",
    reply_to = "finance@example.com",
    attachment_file = ["reports/q3_2023.pdf", "reports/summary.xlsx"]
)

if result.success:
    print("Email sent to:", result.to)
    print("CC:", result.cc)
    print("BCC:", result.bcc)
    print("Sender:", result.sender)
    print("Attachments:", result.attachments)

Dynamic Attachments

load("email", "send")

# Email with dynamically created attachments
result = send(
    subject = "Generated Report",
    html = "<p>Your custom report is attached.</p>",
    to = "client@example.com",
    from_id = "reports",
    attachment = [
        {"name": "report.csv", "content": generate_csv_content()},
        {"name": "chart.txt", "content": "This is a text attachment"}
    ]
)

if result.success:
    print("Email sent with attachments:", result.attachments)

API Reference

Function: send

Sends an email via Resend API.

Parameters

ParameterTypeRequiredDescription
subjectstringYesEmail subject line
htmlstringNo*HTML body content
textstringNo*Plain text body content
markdownstringNo*Markdown body content (converted to HTML)
tostring or list of stringsYesRecipient email address(es)
ccstring or list of stringsNoCC recipient email address(es)
bccstring or list of stringsNoBCC recipient email address(es)
senderstringNo**Full sender email address
from_idstringNo**Sender ID (used with domain)
reply_tostringNoReply-to email address
reply_idstringNoReply-to ID (used with domain)
attachment_filestring or list of stringsNoFile path(s) to attach
attachmentlist of dictsNoList of {"name": string, "content": string} objects

*At least one of html, text, or markdown must be provided. **At least one of sender or from_id must be provided.

Returns

A struct containing the following fields:

FieldTypeDescription
successboolWhether the email was sent successfully
errorstringError message if the email failed to send
idstringThe unique identifier of the sent email
senderstringThe sender's email address
tolist of stringsList of recipient email addresses
cclist of stringsList of CC recipient email addresses
bcclist of stringsList of BCC recipient email addresses
reply_tostringThe reply-to email address
subjectstringThe email subject
body_htmlstringThe HTML content of the email
body_textstringThe plain text content of the email
attachmentslist of dictsList of attachment details (name, content)

When an error occurs:

  • success will be False
  • error will contain the error message
  • All other fields will be None

Environment Integration

For deployment environments, you can use environment variables:

module, _ := base.NewConfigurableModuleWithOptions(
    base.WithConfigEnvVar("resend_api_key", "RESEND_API_KEY"),
    base.WithConfigEnvVar("sender_domain", "EMAIL_SENDER_DOMAIN"),
)
emailModule := &email.Module{CfgMod: module}

License

This project is licensed under the MIT License.

FAQs

Package last updated on 10 May 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.