English 中文(简体)
Rails ActionMailer problems on Mac
原标题:

I ve been working on learning to use Rails the last couple days and I ve run into something that I haven t been able to solve with Google.

So I m just creating a basic contact form that sends an email. Everything seems to be working ok in testing, which tells me that the form is working, and ActionMailer was implemented correctly, however, I m having trouble configuring ActionMailer. I m running OSX 10.6.2. I have postfix running and have verified that it s running using telnet localhost 25. When I try to use the form I get a "Connection refused" error.

This is my current configuration:

config.action_mailer.smtp_settings = {
  :address  =>  localhost ,
  :port     => 25
}

I thought I might need to set :domain but I m kind of confused on what that should be set to in this situation.

最佳回答

My life has been roughly 100x easier running :sendmail on my mac as a delivery method on my mac rather than :smtp, you might want to try giving that a shot. In this answer, I am assuming that you just want mail delivery on your Mac and don t actually care how it works.

The other thing I do, if I m going to be connected to the net all the time on a project, is to configure my outgoing ActionMailer-originated mail to go through gmail rather than my local mac.

ActionMailer::Base.delivery_method = :smtp

ActionMailer::Base.smtp_settings = {
:enable_starttls_auto => true,
  :address        => "smtp.gmail.com",
  :port           => 587,
  :domain         => "example.com",
  :authentication => :plain,
  :user_name  => "address@example.com",
  :password  => "secret"
}

This is for a custom domain called example.com that is set up on google apps for domains. You can also just create a gmail account and send things through there. (By changing all instances of example.com to gmail.com)

问题回答

You need to start the postfix daemon. you can tell if your port is open by typing in a terminal

telnet localhost 25

which will try to connect to the 25 port. It wont connect if postfix isnt running, if it does, hit ctl-] to stop the connection and quit to quit telnet.

If it doesn t connect, you need to start the postfix daemon:

sudo launchctl start org.postfix.master

and then try to connect with telnet. it should connect. Now you are ready to send emails from your ActionMailer class.

sudo launchctl stop org.postfix.master

stops the postfix daemon

I followed this guide and everything works correctly. Mainly:

sudo postfix start

then

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
   :address => "localhost",
   :port => 25
}

Does it work if you substitute 127.0.0.1 for localhost to see if this is an IPv4 vs. IPv6 thing or an issue with your resolver?

Another great way of sending and verifying mails when development is using enter link description here.

Quote from their website:

MailCatcher runs a super simple SMTP server which catches any message sent to it to display in a web interface. Run mailcatcher, set your favourite app to deliver to smtp://localhost:1025 instead of your default SMTP server, then check out http://localhost:1080 to see the mail that s arrived so far.

It intercepts mail to all recipients and hence makes it really easy to check all mail in one place.





相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签