Class List Method List File List

# Class: VertxMail::MailClient

Inherits:
  Object
  - Object
  - VertxMail::MailClient
  show all
Defined in:
  /Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-mail/mail_client.rb

## Overview

SMTP mail client for Vert.x

A simple asynchronous API for sending mails from Vert.x applications

## Direct Known Subclasses

MailService

## Class Method Summary (collapse)

- + (::VertxMail::MailClient) create_non_shared(vertx = nil, config = nil)
  create a non shared instance of the mail client.
- + (::VertxMail::MailClient) create_shared(vertx = nil, config = nil, poolName = nil)
  Create a Mail client which shares its data source with any other Mongo clients created with the same pool name.

## Instance Method Summary (collapse)

- - (void) close
  close the MailClient.
- - (self) send_mail(email = nil) { ... }
  send a single mail via MailClient.

## Class Method Details

### + (`::VertxMail::MailClient`) create_non_shared(vertx = nil, config = nil)

create a non shared instance of the mail client

Parameters:

- vertx (`::Vertx::Vertx`) (defaults to: `nil`) —
  the Vertx instance the operation will be run in
- config (`Hash`) (defaults to: `nil`) —
  MailConfig configuration to be used for sending mails

Returns:

- (`::VertxMail::MailClient`) —
  MailClient instance that can then be used to send multiple mails

Raises:

- (`ArgumentError`)

    23
    24
    25
    26
    27
    28
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-mail/mail_client.rb', line 23

    def self.create_non_shared(vertx=nil,config=nil)
      if vertx.class.method_defined?(:j_del) && config.class == Hash && !block_given?
        return ::Vertx::Util::Utils.safe_create(Java::IoVertxExtMail::MailClient.java_method(:createNonShared, [Java::IoVertxCore::Vertx.java_class,Java::IoVertxExtMail::MailConfig.java_class]).call(vertx.j_del,Java::IoVertxExtMail::MailConfig.new(::Vertx::Util::Utils.to_json_object(config))),::VertxMail::MailClient)
      end
      raise ArgumentError, "Invalid arguments when calling create_non_shared(vertx,config)"
    end

### + (`::VertxMail::MailClient`) create_shared(vertx = nil, config = nil, poolName = nil)

Create a Mail client which shares its data source with any other Mongo clients created with the same pool name

Parameters:

- vertx (`::Vertx::Vertx`) (defaults to: `nil`) —
  the Vert.x instance
- config (`Hash`) (defaults to: `nil`) —
  the configuration
- poolName (`String`) (defaults to: `nil`) —
  the pool name

Returns:

- (`::VertxMail::MailClient`) —
  the client

Raises:

- (`ArgumentError`)

    35
    36
    37
    38
    39
    40
    41
    42
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-mail/mail_client.rb', line 35

    def self.create_shared(vertx=nil,config=nil,poolName=nil)
      if vertx.class.method_defined?(:j_del) && config.class == Hash && !block_given? && poolName == nil
        return ::Vertx::Util::Utils.safe_create(Java::IoVertxExtMail::MailClient.java_method(:createShared, [Java::IoVertxCore::Vertx.java_class,Java::IoVertxExtMail::MailConfig.java_class]).call(vertx.j_del,Java::IoVertxExtMail::MailConfig.new(::Vertx::Util::Utils.to_json_object(config))),::VertxMail::MailClient)
      elsif vertx.class.method_defined?(:j_del) && config.class == Hash && poolName.class == String && !block_given?
        return ::Vertx::Util::Utils.safe_create(Java::IoVertxExtMail::MailClient.java_method(:createShared, [Java::IoVertxCore::Vertx.java_class,Java::IoVertxExtMail::MailConfig.java_class,Java::java.lang.String.java_class]).call(vertx.j_del,Java::IoVertxExtMail::MailConfig.new(::Vertx::Util::Utils.to_json_object(config)),poolName),::VertxMail::MailClient)
      end
      raise ArgumentError, "Invalid arguments when calling create_shared(vertx,config,poolName)"
    end

## Instance Method Details

### - (`void`) close

This method returns an undefined value.

close the MailClient

Raises:

- (`ArgumentError`)

    56
    57
    58
    59
    60
    61
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-mail/mail_client.rb', line 56

    def close
      if !block_given?
        return @j_del.java_method(:close, []).call()
      end
      raise ArgumentError, "Invalid arguments when calling close()"
    end

### - (`self`) send_mail(email = nil) { ... }

send a single mail via MailClient

Parameters:

- email (`Hash`) (defaults to: `nil`) —
  MailMessage object containing the mail text, from/to, attachments etc

Yields:

- will be called when the operation is finished or it fails (may be null to ignore the result)

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    47
    48
    49
    50
    51
    52
    53
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-mail/mail_client.rb', line 47

    def send_mail(email=nil)
      if email.class == Hash && block_given?
        @j_del.java_method(:sendMail, [Java::IoVertxExtMail::MailMessage.java_class,Java::IoVertxCore::Handler.java_class]).call(Java::IoVertxExtMail::MailMessage.new(::Vertx::Util::Utils.to_json_object(email)),(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result != nil ? JSON.parse(ar.result.toJson.encode) : nil : nil) }))
        return self
      end
      raise ArgumentError, "Invalid arguments when calling send_mail(email)"
    end