Asia/Kolkata
ProjectsSeptember 29, 2024

Building a Transactional Mass Mailer with Rails

image
RubyMassMailer is a Rails API-only application designed to provide a flexible platform for sending mass transactional emails. Whether you're sending order confirmations, password resets, or any other type of email, RubyMassMailer makes it easy to manage and send your emails.
  • API-Only: Lightweight and efficient API-only Rails application.
  • Mass Email Sending: Easily send transactional emails to multiple recipients.
  • Customizable Templates: Use customizable email templates to fit your branding and message.
  • Queue Processing: Background job processing for handling email queues.
  • Ruby 3.0
  • Rails 6.0 or higher
  1. Clone the repository:
git clone https://github.com/greeenboi/RubyMassMailer.git
cd RubyMassMailer
  1. Install the dependencies:
bundle install
  1. Create and Fill the Enviroment file .env.example -> .env
  2. Start the server:
rails s
Within ./config/initializers/mailjet adjust the api v3.1 or v3.0 depending on whether you want to send batch mails or not (check your mailjet config) Configure the mailer settings in config/environments/production.rb:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: ENV['SMTP_ADDRESS'],
port: ENV['SMTP_PORT'],
user_name: ENV['SMTP_USER_NAME'],
password: ENV['SMTP_PASSWORD'],
authentication: 'plain',
enable_starttls_auto: true
}
Sending Emails To send an email, make a POST request to the /api/v1/emails endpoint.
Sample JS script
const fs = require('fs');
const path = require('path');
const axios = require('axios');
const FormData = require('form-data');

const API_URL = 'http://localhost:3000/api/v1/emails'; 
const RECIPIENT_EMAIL = 'coolman@email.com';
const ATTACHMENT_PATH = './yummy.jpg';

async function sendTestEmail() {
try {
  const formData = new FormData();
  formData.append('email[to]', RECIPIENT_EMAIL);
  formData.append('email[to_name]', 'Test Recipient');
  formData.append('email[subject]', 'Test Email from Demo Server');
  formData.append('email[text_content]', 'This is a test email sent from our demo server.');
  formData.append('email[html_content]', '<h1>Test Email</h1><p>This is a <strong>test email</strong> sent from our demo server.</p>');

  // Add attachment if the file exists
  if (fs.existsSync(ATTACHMENT_PATH)) {
    const attachment = fs.createReadStream(ATTACHMENT_PATH);
    formData.append('email[attachments][]', attachment, path.basename(ATTACHMENT_PATH));
  }
  // ...existing code...
  } catch (error) {
    console.error(error);
  }
}

Recent projects

The Eden Project

The Eden Project

Avatar
What if music wasn't so inaccessible..
Run over a Deer

Run over a Deer

Avatar
A Silly little game based on the hit movie Over The Hedge
Just a Walkthrough

Just a Walkthrough

Avatar
Framework-agnostic onboarding walkthrough / product tour library with optional React provider & Tailwind/shadcn support.
Suvan GSgreeenboiGreenArcadeSuvan GSgreeenboiGreenArcadeSuvan GSgreeenboi
Suvan GSgreeenboiGreenArcadeSuvan GSgreeenboiGreenArcadeSuvan GSgreeenboi