class

EMail::ConcurrentSender

Inherits Reference / Object

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

Constructors

new(config : EMail::Client::Config)

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

Source
new(*args, **named_args)

Sends one email with given client settings as several arguments.

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

Source

Instance methods

connection_interval=(new_interval : Int32)

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

Source
enqueue(messages : Array(Message))

Encueues email messages at the same time.

Source
enqueue(message : Message)

Enqueues a email message.

Source
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.

Source
number_of_connections=(new_value : Int32)

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

Source
start(number_of_connections : Int32 | Nil = nil, messages_per_connection : Int32 | Nil = nil, connection_interval : Int32 | Nil = nil, &)

Starts sending emails with given parameters.

Source