Skip to contents

Introduction

artsend provides email sending functionality for the Artalytics platform using the Resend API. It’s a pure email service integration without database dependencies, enabling:

  • Contact forms - Gallery visitor messages to artists
  • Notifications - Waitlist confirmations, pilot program invitations
  • Transactional emails - Whitepaper delivery, access grants
  • Professional templates - Pre-built HTML email designs

Installation

Install from the Artalytics GitHub organization:

# Requires GITHUB_PAT for private repos
pak::pkg_install("artalytics/artsend")

Configuration

Set your Resend API key before using any email functions. Get your API key from the Resend Dashboard.

# Set environment variable
Sys.setenv(ART_RESEND_KEY = "re_xxxxxxxxxxxxx")

# Verify configuration
artsend::is_resend_configured()
#> [1] TRUE

For persistent configuration, add to your .Renviron file:

ART_RESEND_KEY=re_xxxxxxxxxxxxx

Security note: Never commit API keys to version control. Use environment variables or secure credential management.

Quick Start

Send a Contact Form Email

The most common use case is sending messages from gallery visitors to artists:

library(artsend)

result <- send_contact_email(
  to = "artist@example.com",
  visitor_name = "John Doe",
  visitor_email = "john@example.com",
  msg = "I love your artwork! Can we discuss a commission?",
  art_title = "Sunset Dreams",
  art_url = "https://cdn.artalytics.app/..."
)

if (result$success) {
  message("Email sent! ID: ", result$message_id)
} else {
  warning("Failed: ", result$error)
}

Send Waitlist Confirmation

Confirm when artists join the pilot program waiting list:

result <- send_waitlist_confirm(
  to = "newartist@example.com",
  artist_name = "Jane Artist",
  waitlist_id = "wl-12345"
)

Send Whitepaper to Investors

Deliver whitepaper with personalized messaging by user type:

result <- send_wp_email(
  to = "investor@vc.com",
  usr_type = "investor"  # "artist", "investor", or "other"
)

Response Handling

All email functions return a standardized response list:

list(
  success = TRUE,           # Logical indicating success
  message_id = "abc123",    # Resend message ID (if successful)
  error = NULL              # Error message (if failed)
)

Always check the success field before proceeding. Here’s a pattern using simple logging helpers:

# Define logging helpers for your application
log_email_sent <- function(id) {
    message("[EMAIL] Sent successfully: ", id)
}

log_error <- function(msg) {
    warning("[ERROR] ", msg)
}
result <- send_contact_email(...)

if (result$success) {
  # Log success, update database, etc.
  log_email_sent(result$message_id)
} else {
  # Handle error, retry, alert admin, etc.
  log_error(result$error)
}

Email Validation

Validate email addresses before sending:

validate_email_fmt("user@example.com")
#> [1] TRUE

validate_email_fmt("invalid.email")
#> [1] FALSE

The validation uses a basic regex pattern that catches most formatting errors:

  • Requires @ symbol
  • Requires domain with .
  • Requires at least 2 characters after final dot
  • Allows common special characters in local part

Error Handling

Functions handle errors gracefully and return descriptive messages:

# Missing API key
Sys.unsetenv("ART_RESEND_KEY")
result <- send_contact_email(...)
result$error
#> "Configuration error: Resend API key not found..."

# Invalid email format
result <- send_contact_email(to = "not-an-email", ...)
result$error
#> "Recipient email (to) is not a valid email address"

# API failure
result <- send_contact_email(...)  # API down
result$error
#> "Email sending failed: Connection timeout..."

What’s Next?

Additional Resources

Support

For issues or questions:

  • GitHub Issues: https://github.com/artalytics/artsend/issues
  • Email: support@artalytics.app