Class: VertxMail::MailClient

Inherits:
Object
  • Object
show all
Defined in:
/Users/julien/java/vertx-aggregator/modules/vertx-mail-client/vertx-mail-client/src/main/resources/vertx-mail/mail_client.rb

Overview

SMTP mail client for Vert.x

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

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (::VertxMail::MailClient) create(vertx = nil, config = nil)

create an instance of MailClient that is running in the local JVM

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:

Raises:

  • (ArgumentError)


22
23
24
25
26
27
# File '/Users/julien/java/vertx-aggregator/modules/vertx-mail-client/vertx-mail-client/src/main/resources/vertx-mail/mail_client.rb', line 22

def self.create(vertx=nil,config=nil)
  if vertx.class.method_defined?(:j_del) && config.class == Hash && !block_given?
    return ::VertxMail::MailClient.new(Java::IoVertxExtMail::MailClient.java_method(:create, [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))))
  end
  raise ArgumentError, "Invalid arguments when calling create(vertx,config)"
end

Instance Method Details

- (void) close

This method returns an undefined value.

close the MailClient

Raises:

  • (ArgumentError)


41
42
43
44
45
46
# File '/Users/julien/java/vertx-aggregator/modules/vertx-mail-client/vertx-mail-client/src/main/resources/vertx-mail/mail_client.rb', line 41

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) the result JsonObject currently only contains {"result":"success"}

Returns:

  • (self)

Raises:

  • (ArgumentError)


32
33
34
35
36
37
38
# File '/Users/julien/java/vertx-aggregator/modules/vertx-mail-client/vertx-mail-client/src/main/resources/vertx-mail/mail_client.rb', line 32

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