如何配置动作邮件程序(我应该注册域)? [英] How to configure action mailer (should I register domain)?

查看:98
本文介绍了如何配置动作邮件程序(我应该注册域)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Ruby on Rails创建一个简单的非营利应用程序。为了能够通过Gmail发送电子邮件,我必须设置以下设置:

I am creating a simple non-profit application with Ruby on Rails. I have to set up the following settings in order to be able to send emails with Gmail:

Depot::Application.configure do

config.action_mailer.delivery_method = :smtp

config.action_mailer.smtp_settings = {
    address:"smtp.gmail.com",
    port:587,
    domain:"domain.of.sender.net",
    authentication: "plain",
    user_name:"dave",
    password:"secret",
    enable_starttls_auto: true
}

end

I

I am completely new with this stuff and have no idea what exactly I should do.


  1. 如果我有gmail帐户,如何填充上面的设置?我
    是否需要购买一个域名,并且可以从Google购买该域名以便
    使用上述设置吗?

  2. 在以下位置设置邮件服务器更好吗?我的电脑?我看着
    教程,但据我了解,我仍然需要购买
    域名。

  1. How to populate the settings above if I have gmail account? Do I need to buy a domain and can be it bought from google in order to use the settings above?
  2. Is it better to set up mail server on my PC? I looked though this tutorial but as far as I understand I still need to buy a domain.

此外,也有人说此处


设置电子邮件服务器是一个困难的过程,涉及许多
个不同的程序,每个程序都需要正确配置。

Setting up an email server is a difficult process involving a number of different programs, each of which needs to be properly configured.

因为这和我的技能差,我正在寻找最简单的解决方案。

because of this and my poor skills I am looking for the simplest solution.

我阅读了Rails动作邮件程序教程,并对这些参数的用途有所了解,但是完全不清楚Gmail和邮件服务器周围的所有情况。

I have read the rails action mailer tutorial and have an idea about what these parameters are used for, but the things around the Gmail and the mail server are not clear at all.

推荐答案

应该/可以在开发生产目的中定义邮件程序的配置此配置的含义是,当您使用 actionmailer 进行设置时,将使用这些SMTP选项。您可以使用一个简单的邮件程序,如下所示:

The configuration of your mailer should/can be defined in both development and production the purpose of this configuration is that when you set this up when you use the actionmailer these SMTP options will be used. You could have a simple mailer like the following:

邮件程序

class UserMailer < ActionMailer::Base
  default :from => DEFAULT_FROM
  def registration_confirmation(user)
    @user = user
    @url = "http://portal.herokuapp.com/login"
    mail(:to => user.email, :subject => "Registered")

  end
end

控制器

 def create
    @title = 'Create a user'
    @user = User.new(params[:user])

    if @user.save
      UserMailer.registration_confirmation(@user).deliver
      redirect_to usermanagement_path
      flash[:success] = 'Created successfully.'
    else
      @title = 'Create a user'
      render 'new'
    end
  end

所以这里发生的事情是当创建正在使用操作,这会触发邮件程序 UserMailer 在上面的UserMailer中,它使用ActionMailer作为基础。按照下面显示的SMTP设置,可以在 config / environments / production.rb 和development.rb

So what happens here is that when the create action is being used this fires the mailer UserMailer Looking at the above UserMailer it uses the ActionMailer as the base. Following the SMTP setup shown below which can be defined in both config/environments/production.rb and development.rb

您将具有以下内容:

  config.action_mailer.default_url_options = { :host => 'portal.herokuapp.com' }
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
      :address              => 'smtp.gmail.com',
      :port                 => 587,
      :domain               => 'gmail.com',
      :user_name            => 'EMAIL_ADDRESS@gmail.com',
      :password             => 'pass',
      :authentication       => 'login',
      :enable_starttls_auto => true
  }

如果要在开发模式下定义SMTP设置,请替换

If you want to define the SMTP settings in development mode you would replace

config.action_mailer.default_url_options = { :host => 'portal.herokuapp.com' }

with

config.action_mailer.default_url_options = { :host => 'IP ADDRESS HERE:3000' }

这应该是一个足够详尽的解释,可以帮助您开始正确的方向。

This should be a thorough enough explanation to kick start you in the right direction.

这篇关于如何配置动作邮件程序(我应该注册域)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆