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..
Related
I am working with rails 3.2 and ruby 2.1.2p95. Through my application, sending 1000+ of emails. I want to send few email from smtp and few emails from sendgrid. So I have configured like below in Notifier.rb file
after_filter :set_delivery_options, :except => [:method1]
def set_delivery_options
message.delivery_method.settings.merge!(
:address => "smtp.gmail.com",
:port => 587,
:domain => "xxxxxxxx",
:user_name => "xxxxxxxxxxxxx",
:password => "xxxxxxxxxxxxx",
:authentication => "plain",
:enable_starttls_auto => true
)
end
My method is like below:
def customer_mailing(customer)
mail(
:to => customer.user.email,
:subject => "Testing",
#:bcc => EMAIL_BCC,
:content_type => "text/html"
)
set_headers
end
Whenever I call the above method, the mail is sending twice or more in some times on production server.
I'm trying to send a simple email using my Gmail account through ruby's mail gem but the email is never sent nor received. I followed the steps from a similar question but I wasn't sure what to put under the domain field. I believe this may be my issue but I'm not sure.
my code:
require 'mail'
options = { :address => "smtp.gmail.com",
:port => 587,
:domain => 'your.host.name',
:user_name => 'REMOVED',
:password => 'REMOVED',
:authentication => 'plain',
:enable_starttls_auto => true }
Mail.defaults do
delivery_method :smtp, options
end
mail = Mail.new do
from 'REMOVED'
to 'REMOVED'
subject 'This is a test email'
body 'test'
end
I don't see where you are calling the deliver method to send the email. Based on the documentation, there's a couple of ways to do that:
Mail.deliver do
from 'me#test.lindsaar.net'
to 'you#test.lindsaar.net'
...
end
or
mail = Mail.new do
from 'me#test.lindsaar.net'
to 'you#test.lindsaar.net'
...
end
mail.deliver!
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
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
}
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