class EMail::ConcurrentSender

Overview

Utility object for concurrent email sending.

rcpt_list = ["a@example.com", "b@example.com", "c@example.com", "d@example.com"]

# Set SMTP client configuration
config = EMail::Client::Config.new("your.mx.example.com", 25)

# Create concurrent sender object
sender = EMail::ConcurrentSender.new(config)

# Sending emails with concurrently 3 connections.
sender.number_of_connections = 3

# Sending max 10 emails by 1 connection.
sender.messages_per_connection = 10

# Start email sending.
sender.start do
  # In this block, default receiver is sender
  rcpt_list.each do |rcpt_to|
    # Create email message
    mail = EMail::Message.new
    mail.from "your_addr@example.com"
    mail.to rcpt_to
    mail.subject "Concurrent email sending"
    mail.message "message to #{rcpt_to}"
    # Enqueue the email to sender
    enqueue mail
  end
end

Defined in:

email/concurrent_sender.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(config) #

Creates sender object with given client settings as EMail::Client::Config object.


[View source]
def self.new(*args, **named_args) #

Sends one email with given client settings as several arguments.

Avairable arguments are same as EMail::Client::Conifg.create method.


[View source]

Instance Method Detail

def connection_interval=(new_interval : Int32) #

Sets the interval milliseconds between some connection is closed and new one is opened.


[View source]
def enqueue(messages : Array(Message)) #

Encueues email messages at the same time.


[View source]
def enqueue(message : Message) #

Enqueues a email message.


[View source]
def messages_per_connection=(new_value : Int32) #

Sets the maximum number of email messages sent by one SMTP connection.

When the number of sent emails by some SMTP connection reaches this parameter, the current connection will be closed and new one will be opened.


[View source]
def number_of_connections=(new_value : Int32) #

Sets the maximum number of SMTP connections established at the same time.


[View source]
def start(number_of_connections : Int32? = nil, messages_per_connection : Int32? = nil, connection_interval : Int32? = nil, &) #

Starts sending emails with given parameters.


[View source]