dongzan1970 2013-12-27 18:24
浏览 31
已采纳

为什么我需要一个电子邮件帐户来发送ruby上的邮件而不需要这样的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?

  • 写回答

1条回答 默认 最新

  • doutangqi4444 2013-12-27 18:28
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大