ProductPromotion
Logo

Ruby

made by https://0x3d.site

GitHub - benprew/pony: The express way to send mail from Ruby.
The express way to send mail from Ruby. Contribute to benprew/pony development by creating an account on GitHub.
Visit Site

GitHub - benprew/pony: The express way to send mail from Ruby.

GitHub - benprew/pony: The express way to send mail from Ruby.

Pony, the express way to send email in Ruby

Overview

Ruby no longer has to be jealous of PHP's mail() function, which can send an email in a single command.

Pony.mail(:to => '[email protected]', :from => '[email protected]', :subject => 'hi', :body => 'Hello there.')
Pony.mail(:to => '[email protected]', :html_body => '<h1>Hello there!</h1>', :body => "In case you can't read html, Hello there.")
Pony.mail(:to => '[email protected]', :cc => '[email protected]', :from => '[email protected]', :subject => 'hi', :body => 'Howsit!')

Any option key may be omitted except for :to. See List Of Options section for the complete list.

Transport

Pony uses /usr/sbin/sendmail to send mail if it is available, otherwise it uses SMTP to localhost.

This can be overridden if you specify a via option:

Pony.mail(:to => '[email protected]', :via => :smtp) # sends via SMTP
Pony.mail(:to => '[email protected]', :via => :sendmail) # sends via sendmail

You can also specify options for SMTP:

Pony.mail({
  :to => '[email protected]',
  :via => :smtp,
  :via_options => {
    :address        => 'smtp.yourserver.com',
    :port           => '25',
    :user_name      => 'user',
    :password       => 'password',
    :authentication => :plain, # :plain, :login, :cram_md5, no auth by default
    :domain         => "localhost.localdomain" # the HELO domain provided by the client to the server
  }
})

Gmail example (with TLS/SSL)

Pony.mail({
  :to => '[email protected]',
  :via => :smtp,
  :via_options => {
    :address              => 'smtp.gmail.com',
    :port                 => '587',
    :enable_starttls_auto => true,
    :user_name            => 'user',
    :password             => 'password_see_note',
    :authentication       => :plain, # :plain, :login, :cram_md5, no auth by default
    :domain               => "localhost.localdomain" # the HELO domain provided by the client to the server
  }
})

Note: If you use 2 step verification, you will have to generate an application specific password and NOT use your normal password - see https://support.google.com/accounts/answer/185833?hl=en

And options for Sendmail:

Pony.mail({
  :to => '[email protected]',
  :via => :sendmail,
  :via_options => {
    :location  => '/path/to/sendmail', # defaults to 'which sendmail' or '/usr/sbin/sendmail' if 'which' fails
    :arguments => '-t' # -t and -i are the defaults
  }
})

If you're using smtp, set :arguments => ''.

Attachments

You can attach a file or two with the :attachments option:

Pony.mail(..., :attachments => {"foo.zip" => File.read("path/to/foo.zip"), "hello.txt" => "hello!"})

Note: An attachment's mime-type is set based on the filename (as dictated by the ruby gem mime-types). So 'foo.pdf' has a mime-type of 'application/pdf'

Custom Headers

Pony allows you to specify custom mail headers

Pony.mail(
  :to => '[email protected]',
  :headers => { "List-ID" => "...", "X-My-Custom-Header" => "what a cool custom header" }
)

Add additional options for headers in each part of letter (text, html)

Pony.mail(
  :body => 'test',
  :html_body => 'What do you know, Joe?',
  :attachments => {"foo.txt" => "content of foo.txt"},
  :body_part_header => { content_disposition: "inline" }
)

This will add option 'Content-Disposition: inline' for text part header of letter.

Also you can add additional options for html part of latter, e.g.:

:html_body_part_header => { content_disposition: "inline" }

List Of Options

You can get a list of options from Pony directly:

Pony.permissable_options

Options passed pretty much directly to Mail

attachments # see Attachments section
bcc
body # the plain text body
body_part_header # see Custom headers section
cc
charset # In case you need to send in utf-8 or similar
content_type
from
headers # see Custom headers section
html_body # for sending html-formatted email
html_body_part_header # see Custom headers section
message_id
reply_to
sender  # Sets "envelope from" (and the Sender header)
smtp_envelope_to
subject
text_part_charset # for multipart messages, set the charset of the text part
to

Other options via # :smtp or :sendmail, see Transport section via_options # specify transport options, see Transport section

Default Options

Default options can be set so that they don't have to be repeated. The default options you set will be overriden by any options you pass in to Pony.mail()

Pony.options = { :from => '[email protected]', :via => :smtp, :via_options => { :host => 'smtp.yourserver.com' } }
Pony.mail(:to => 'foo@bar') # Sends mail to foo@bar from [email protected] using smtp
Pony.mail(:from => '[email protected]', :to => 'foo@bar') # Sends mail to foo@bar from [email protected] using smtp

Override Options

Override options can be set so that the override value is always be used, even if a different value is passed in to Pony.options() or Pony.mail(). This can be used to configure a development or staging environment.

Pony.override_options = { :to => '[email protected]' }
Pony.mail(:to => 'foo@bar') # Sends mail to [email protected] instead of foo@bar

Testing/Debugging Aids

Build Status

Subject prefix

Prepends a string to the subject line. This is used to identify email sent from a specific environment.

Pony.subject_prefix('Prefix:')

Append options to body

Append the options passd into Pony.mail to the body of the email. Useful for debugging.

Pony.append_inputs

Using Pony with Testing or Spec'ing Libraries

As pony relies on mail to send the mails, you can also use its TestMailer in your tests.

Pony.override_options = { :via => :test }
Pony.mail(:to => 'foo@bar')
Mail::TestMailer.deliveries.length
=> 1

For further examples see the corresponding section of mail's readme

Help

If you need help using Pony, or it looks like you've found a bug, email [email protected]. The full forum is https://groups.google.com/forum/#!forum/ponyrb

Meta

Authors

Changelog

1.13.2

  • Bump rake version, bump outdated gems (rspec and mini_mime)

1.13

  • fix bug: suppress potential error message from "which"
  • fix bug: Add support for passing empty hashes as attachment

1.12

  • fix bug: NoMethodError when using mail 2.7.0

1.11

  • Improved handling of mails with both text and html bodies and attachments

1.10

  • Add subject_prefix, append_options and override_options

1.9

  • Allow options to be queried from the gem

1.8

  • Add additional options for headers in each part of letter

1.7

  • Better default content_type with attachments

1.6

  • Unknown options are passed directly to mail to handle. Remove deprecated syntax

1.5.1

  • Loosen mail dependency to >= 2.0 instead of > 2.0

1.5

  • Specify content-id of attachments as filename@hostname

1.4.1

  • Update gemfile

1.4

  • Updated docs

1.3

  • Add new option :text_part_charset, which allows you to specify the charset for the text portion

1.2

  • Remove limitations on :via, and let mail handle it (this means you can say things like :via => test)
  • Add reply-to option and a bundler file

1.1

  • Add default options

1.0

  • Convert to using Mail as the mail-generation backend, instead of TMail

0.9.1

  • provide the ability to set custom mail headers with something like: Pony.mail(:headers => {"List-ID" => "..."})
  • provide the ability to set the Message-Id from Pony.mail

0.9

  • merge in kalin's fixes to use tmail.destinations instead of trying to parse tmail.to, tmail.cc and tmail.bcc. New specs to test functionality

0.8

  • Fix bug that was allowing nil :bcc and :cc options to be passed to smtp

0.7

  • Pass :cc and :bcc options to sendmail appropriately

0.6

  • Add :bcc capability
  • Add :charset capability
  • Add complete list of options to readme
  • fix bug: readme examples

0.5

  • default location of sendmail to /usr/sbin/sendmail if sendmail not in path
  • fix bug: README not showing password option (listed as pass)

0.4.1

  • Add :cc capability
  • fix bug: resolve body not displaying when attachments sent

0.4

  • Implemented file attachments option
  • use TLS if :tls => true

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory