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.

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

报告相同问题?

悬赏问题

  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)