简体   繁体   English

为什么我需要一个电子邮件帐户才能在ruby上发送邮件,而在php上却不需要这样?

[英]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. 我在php中使用了mail()命令,并且在没有定义任何登录名和密码的情况下也能正常工作。 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. 现在,我要学习Ruby on Rails,它已写在指南中,我需要配置一些电子邮件附件才能发送电子邮件。 Why do I need one on Ruby and don't need any on php? 为什么我在Ruby上需要一个而在php上却不需要呢? What is difference and what is better? 有什么区别,什么更好?

generally speaking you don't need one on rails, anymore than you need one in php. 一般来说,您不需要一个就可以了,比您需要一个更不需要使用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). 在运行本地邮件服务器/中继代理的连接良好的服务器上,您可以将rails设置为使用本地sendmail配置,通常这是php默认情况下使用mail()命令执行的操作。 see http://guides.rubyonrails.org/action_mailer_basics.html specifically section 6.1 请参阅http://guides.rubyonrails.org/action_mailer_basics.html专门的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. 还有gmail等配置。

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. 我要补充一点,大多数教程显示正在使用的电子邮件帐户的原因是,它们正在localhost上运行,这很有可能是没有很好的连接并且没有适当的sendmail配置。 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. 因此,为了使其正常运行并实际查看来自应用程序的电子邮件,使用gmail等中继是一种安全的选择/默认设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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