Ruby Pony alternative for Ruby 1.9? - ruby

Pony is broken in ruby 1.9. Does any recommend any alternatives for me so I can send mail through my Gmail account? Cheers

Pony works for me in Ruby 1.9, and I'm also using the gmail SMTP server. Here's how I have it set up...
require 'pony'
Pony.mail(:to => 'real_mail#yahoo.com', :via => :smtp, :via_options => {
:address => 'smtp.gmail.com',
:port => '587',
:enable_starttls_auto => true,
:user_name => 'id_gmail',
:password => 'parola_gmail',
:authentication => :plain,
:domain => "HELO",
},
:subject => 'Test email', :body => 'Test for Pony email through gmail SMTP server.')

Have you tried Mail from Mikel Lindsaar? It's got really great syntax

Related

Reading Emails via IMAP / SMTP through 'Mail' gem

Is there a way to receive emails via IMAP or SMTP through the 'mail' gem?
The documentation only seems to mention POP3:
Mail.defaults do
retriever_method :pop3, :address => "pop.gmail.com",
:port => 995,
:user_name => '<username>',
:password => '<password>',
:enable_ssl => true
end
The documentation actually talks directly about SMTP.
Mail.defaults do
delivery_method :smtp, address: "localhost", port: 1025
end
That is how you default to sending via SMTP.
To receive, instead of using delivery_method use retriever_method
IMAP works by simply adding this:
Mail.defaults do
retriever_method :imap, :address => 'imap.gmail.com',
:port => 993,
:user_name => '<username>',
:password => '<password>'
:enable_ssl => true
end
I'm still not able to get SMTP retrieval to work..

Ruby gem 'Mail' setting up with SMTP

So I am testing out the Ruby gem 'Mail'. Below is my code. According to the sysadmin, there is no authentication necessary to send out by SMTP and the server is allowed to send by SMTP. If that makes sense.
I have used the 'net/smtp' which worked fine but I can't seem to get this 'Mail' gem to work for me. It's not giving me any errors so I'm not sure what the issue is. I am a complete ruby noob at this.
#testing out mailer
require 'mail'
Mail.defaults do
delivery_method :smtp, {
:address => '10.18.34.18',
:port => '25',
:user_name => 'anonymous',
:password => 'anonymous',
:authentication => 'plain',
:enable_starttls_auto => true}
end
mail = Mail.new do
from 'server#company.com'
to 'cvu#company.com'
subject 'This is a test email'
body File.read('test.txt')
end
mail.to_s
Try calling mail.deliver!, calling to_s just returns you a string representation of the object.
Alternatively you can call deliver with a block instead of calling new, e.g.
mail = Mail.deliver do
from 'server#company.com'
to 'cvu#company.com'
subject 'This is a test email'
body File.read('test.txt')
end
In addition to what struthersneil stated, I had to remove the authentication like so:
require 'mail'
Mail.defaults do
delivery_method :smtp, {
:address => '10.18.34.18',
:port => '25',
:enable_starttls_auto => true}
end

Actionmailer - heroku app

This is a newbie question so please excuse me, I have been working with rails, but this is the first time i am trying to require gems from a heroku app that does not include rails - just a plain Ruby app.
ok I have a app.rb file looking like this:
require "sinatra"
require 'koala'
require 'action_mailer'
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "smtp.sendgrid.net",
:port => 587,
:domain => "MYDOMAIN",
:authentication => :plain,
:user_name => "USER_NAME",
:password => "PASSWORD",
:enable_starttls_auto => true
}
ActionMailer::Base.view_paths= File.dirname(__FILE__)
class TestMailer < ActionMailer::Base
default :from => "MY_EMAIL"
def welcome_email
mail(:to => "MY_EMAIL", :subject => "Test mail", :body => "Test mail body")
end
end
What I would like to do is run
TestMailer::deliver_test_email
in the console and get the details or run
TestMailer::deliver_test_email.deliver
to send a test email
but all i get is :
NameError: uninitialized constant Object::TestMailer
I have included actionmailer in the Gemfile and its also in the Gemfile.lock
I am sure it is something straight forward for an experienced Ruby dev, but I am struggling could anyone help me please?
Thanks
After a few hours of testing and research I ended up using Mail instead, this was my final code which when run works fine, I hope it helps anyone who is having the same issues as I was :)
require 'mail'
Mail.defaults do
delivery_method :smtp, { :address => "smtp.sendgrid.net",
:port => 587,
:domain => "MY_DOMAIN",
:user_name => "USER_NAME",
:password => "PASSWORD",
:authentication => 'plain',
:enable_starttls_auto => true }
end
mail = Mail.deliver do
to 'EMAIL'
from 'Your Name <NAME#MY_DOMAIN>'
subject 'This is the subject of your email'
text_part do
body 'hello world in text'
end
html_part do
content_type 'text/html; charset=UTF-8'
body '<b>hello world in HTML</b>'
end
end

How to configure Devise email with Heroku and Sendgrid in Rails?

I've got a simple Rails 3.2.7 app with Devise added that is deployed to Heroku with Sendgrid added. It works fine on heroku for everything except when it needs to do a password retrieve which requires sending an email. From all the posts i have read i suspect i am somehow setting up the mail parameters incorrectly. Any suggestions are appreciated.
For config/environments/production.rb i added
config.action_mailer.default_url_options = { :host => 'smtp.sendgrid.net'}
for config/initializers/devise.rb i added
config.mailer_sender = "mail-to-send#from.com"
and for config/environments.rb i added
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'heroku.com',
:enable_starttls_auto => true
}
So, your problem is you were referencing the wrong environment variables. Heroku stores your SendGrid credentials in ENV['SENDGRID_USERNAME'] and ENV['SENDGRID_PASSWORD']. You were using your actual username and password as the key names.
This will work:
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'heroku.com',
:enable_starttls_auto => true
}

Using pony gem and ckeditor in my rails 3 application to send bulk mailing

I am using ckeditor im my application for bulk mailing using pony gem mail is getting sent but I have a couple of problems:
Some tags are also delivered in mail.
If I apply effects to text like bold, italic, underline etc are visible in mail
Image is not visible instead of that {"body"=>" is visible.
Following is the code...
My pony mail function...
params[:l].each do |single_email|
p single_email
Pony.mail(:to => single_email, :from => 'example#example.co.in', :subject => #bmail.subject,
:headers => { "Content-Type" => "text/html"}, :body => #bmail.body, :via => :smtp, :via_options => {
:address => "smtp.gmail.com",
:port => 587,
:domain => 'example.co.in',
:user_name => 'example#example.co.in',
:password => 'paswd',
:authentication => 'plain',
:enable_starttls_auto => true
}) end
Call to ckeditor
%br = cktext_area :body, :body, :ckeditor => {:uiColor => "#AADC6E", :toolbar => "mini"}
%br
Please help me to deliver perfect mail with image and stuffs, plz help me as soon as possible.
Thanz in advance.
try :html_body => #bmail.body
http://rubydoc.info/gems/pony/1.4.1/frames

Resources