简体   繁体   中英

Why do I need an e-mail accaunt to send mails on ruby and don't need such on php?

I used mail() command in php and it worked fine without defining any logins and passwords. Now I am learing Ruby on Rails and it's written in guides that I need to configure some e-mail accaunt to be able to send e-mails. Why do I need one on Ruby and don't need any on php? What is difference and what is better?

generally speaking you don't need one on rails, anymore than you need one in php. It all depends on your hosting setup. On a well connected server running a local mail server/relay agent you can setup rails to use the local sendmail config, this is normally what php does by default with the mail() command). see http://guides.rubyonrails.org/action_mailer_basics.html specifically section 6.1

config.action_mailer.delivery_method = :sendmail
# Defaults to:
# config.action_mailer.sendmail_settings = {
#   location: '/usr/sbin/sendmail',
#   arguments: '-i -t'
# }
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_options = {from: 'no-replay@example.com'}

There are also configs there for gmail, etc.

I'll add that the reason most tutorials show the email account being used is that they are being run on localhost which there is a good chance isn't well connected and doesn't have a working sendmail config in place. So in order to make it work, and actually see emails from the app, using something like gmail to relay is a safe choice/default.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM