我正在尝试在开发模式下发送激活电子邮件,我正在使用application.yml输入我的smtp凭据,不知道我缺少什么但由于某种原因我无法发送激活电子邮件。
application.yml
SMTP_PORT: 587
SMTP_DOMAIN: localhost:3000
SMTP_ADDRESS: smtp.gmail.com
SMTP_USERNAME: myemail@gmail.com
SMTP_PASSWORD: myemailpassword
SMTP_AUTHENTICATION: 'plain'
enable_starttls_auto: true
development.rb
config.action_mailer.raise_delivery_errors = false
config.action_mailer.delivery_method = :file
config.action_mailer.file_settings = { location: 'tmp/mails' }
config.action_mailer.default_url_options = { :host => ENV["URL_HOST"] }
token_mailer.rb
def activation(email, token)
@token_url = edit_activation_url token
mail to: email
end
答案 0 :(得分:6)
在development.rb
中使用它config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:user_name => "your mail",
:password => "your password",
:authentication => :plain,
:enable_starttls_auto => true
}
答案 1 :(得分:2)
设置邮件程序以发送电子邮件
app / mailers / user_mailer.rb中的
app/views/user_emailer/welcome.html.erb
<p>Hi <%= @user.username %>,Welcome to myapp.com</p>
设置视图文件以电子邮件形式发送
if Rails.env != 'test'
email_settings = YAML::load(File.open("#{Rails.root.to_s}/config/email.yml"))
ActionMailer::Base.smtp_settings = email_settings[Rails.env] unless email_settings[Rails.env].nil?
end
设置电子邮件配置
在config / initializers / email_setup.rb
中in config/email.yml
development:
:address: smtp.gmail.com
:port: 587
:authentication: plain
:user_name: milind@gmail.com
:password: password
:enable_starttls_auto: true
production:
:address: smtp.gmail.com
:port: 587
:authentication: plain
:user_name: milind@gmail.com
:password: password
:enable_starttls_auto: true
设置密钥/密码,使用gmail ...进行开发,但使用mailchimp / mandrill作为专业人士
UserMailer.welcome(current_user).deliver
用户邮件发送电子邮件
config.ssh.private_key_path = [
customKey,
"#{ENV['HOME']}/.vagrant.d/insecure_private_key"
]
希望它能帮助.... :)
答案 2 :(得分:0)
在您的development.rb文件中尝试此操作
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:authentication => :plain,
:domain => 'yourdomain.com',
:user_name => 'your_gmail_email',
:password => 'your_password'
}