1.由于网站无需验证,只需一封欢迎邮件,在config/intiailzers/devise.rb里面配置

config.allow_unconfirmed_access_for = nil #2.days

2.配置user--编辑app/models/user.rb文件,先写一下数据这一块

class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, #末尾添加,号
:confirmable, :lockable #添加这一行 # Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
end
 
3.编辑20150504141218_devise_create_users.....对照代码去掉#即可

          ## Confirmable
t.string :confirmation_token #去掉首位注释#号 t.datetime :confirmed_at #去掉首位注释#号 t.datetime :confirmation_sent_at #去掉首位注释#号 t.string :unconfirmed_email # Only if using reconfirmable #去掉首位注释#号 ## Lockable
t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts t.string :unlock_token # Only if unlock strategy is :email or :both #去掉首位注释#号 t.datetime :locked_at #去掉首位注释#号 -----------------------------.

发现报错

rake aborted!
NoMethodError: undefined method `attr_accessible' for User (call 'User.connection' to establish a connection):Class

之后百度找到

http://stackoverflow.com/questions/23743603/undefined-method-attr-accessible-error-for-user

attr_accessible is not available for Rails version 4+. You would have to go with strong parameters.

With Strong Parameters, attribute whitelisting has been moved to controller level. Remove the attr_accessible call from your model.

Here is an example in Rails Guide of how to use Strong Parameters

In your case you can do something like this:

class UsersController < ApplicationController
## ...
def create
@user = User.new(user_params) ## Invoke user_params method
if @user.save
redirect_to @user, notice: 'User was successfully created.'
else
render action: 'new'
end
end
## ... private
## Strong Parameters
def user_params
params.require(:user).permit(:name, :password_digest, :password, :password_confirmation)
end
end

之后就删除了attr_accessible :email, :password, :password_confirmation, :remember_me

end
然后重新部署数据库,才能重新检测同一个邮箱是否接受邮件,你也可以重新换一个邮箱注册,因为没有修改config/下面的文件
rake db:migrate:reset
 
2.先测试下,邮件服务器配置config/initialize/devise.rb

config.mailer_sender = 'XXXXXXXX@qq.com' #将邮件服务器地址写成自己的邮箱,作为发送方邮件

3.编辑/config/application.rb,将下列代码添加到class Application < Rails::Application中即可,本人使用的是qq邮箱发送,需要提前去qq邮箱里面打开相应的smtp服务

config.action_mailer.raise_delivery_errors = true     #注意,在development.rb下需修改成true     
#添加如下几行代码
config.action_mailer.default_url_options = { :host => "localhost:3000" } #提示中有提到需要配置,即执行rails g devise:install
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  :address => "smtp.qq.com",
:port => 25,
:domain => "qq.com", #qq.com
:authentication => :login,#几种认证方式:plain,直接传递;login,Base64码传递;cram_md5,md5加密传递
:user_name => "xxxxxxx@qq.com", #修改邮箱
:password => "xxxxxxxx" #修改正确的密码 }

4.本人是用qq测的,所以也按照上面的方法,但还是不行,页面报错535 Authentication failed

百度了半天还是不行,后来看到了 https://ruby-china.org/topics/8918 这个帖子

看到企业邮箱是加了@XXX.com,那我这个是个人的邮箱,应该不需要就删掉了这些.....

然后ctrl+C关闭rails服务器,然后rake db:migrate:reset,重新注册用户....居然发送成功了,来张截图

rails4.2~devise邮箱测试的更多相关文章

  1. SSL邮件发送(腾讯企业邮箱测试通过,可以支持多附件)

    参考网址:http://www.cnblogs.com/LUA123/p/5575134.html ,谢谢! package net.common.utils.common; import java. ...

  2. C# 发送邮件,QQ企业邮箱测试成功

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.N ...

  3. c# 发送邮箱,企业邮箱测试成功

    今天在项目中需要实现一个发送邮箱的功能,来实现用户邮箱激活功能!!! 之前采用的是个人的邮箱进行测试,一切都是很顺利的,后来换成了公司的企业邮箱,遇到了一点小问题,问题如下: 发送邮件失败,原因:命令 ...

  4. 已使用 163 邮箱测试通过,且支持 SSL 连接。 发送邮件

    示例:Jack 发送一封邮件给 Rose. public class SendMail {     public static void main(String[] args) {         b ...

  5. 杂项之使用qq邮箱发送邮件

    杂项之使用qq邮箱发送邮件 本节内容 特殊设置 测试代码 1. 特殊设置 之前QQ邮箱直接可以通过smtp协议发送邮件,不需要进行一些特殊的设置,但是最近使用QQ邮箱测试的时候发现以前使用的办法无法奏 ...

  6. JavaMail简单版实验测试

    前言: 最近由于实现web商城的自动发送邮件功能的需求,故涉猎的邮箱协议的内部原理.现将简单版的Java Mail实例做个代码展示,并附上其中可能出现的bug贴出,方便感兴趣的读者进行测试! 1.载入 ...

  7. QQ邮箱发送邮件,出现mail from address must be same as authorization user错误

    之前做的一个系统,有个发送邮件的功能,一直能正常使用,今天同事说QQ邮箱发送不了. 立马着手调试,发现服务器一直出现“mail from address must be same as authori ...

  8. qq邮箱发送

    454 Authentication failed, please open smtp flag first!用QQ邮箱测试报错 我用QQ邮箱测试javamail发送邮件的功能,用户名密码设置正确,却 ...

  9. Google Play 购买(IAB)测试流程

    Google Play 购买(IAB)测试流程 0. 前言 虽然Google 官方也有说明,但是说话很含糊(英文原文也很含糊),很多时候不清楚它到底表达什么.而且帮助文档和开发文档是分开的,可能常常出 ...

随机推荐

  1. 分享一个js中的bind方法使用

    来源:http://www.cnblogs.com/yuzhongwusan/archive/2012/02/13/2348782.html Js代码 复制代码 代码如下: var first_obj ...

  2. Host 'XXX' is not allowed to connect to this MySQL server 解决方案/如何开启MySQL的远程帐号

    www.cnblogs.com/zhangzhu/archive/2013/08/22/3274831.html 如何开启MySQL的远程帐号-1)首先以 root 帐户登陆 MySQL 在 Wind ...

  3. eclipse中outline中图标的含义

    outline: 实心的代表方法 空心的代表属性 绿色的圆表示公有public 黄色的菱形表示保护protect 红色的方形表示私有private 蓝色的三角表示default 图形后加字母S代表该属 ...

  4. [题解]UVa 11082 Matrix Decompressing

    开始眨眼一看怎么也不像是网络流的一道题,再怎么看也觉得像是搜索.不过虽然这道题数据范围很小,但也不至于搜索也是可以随随便便就可以过的.(不过这道题应该是special judge,因为一题可以多解而且 ...

  5. python学习之——eclipse+pydev 环境搭建

    最终选用 eclipse+pydev,网上相关资料也是极多的~~~ 1.安装python: 2.安装eclipse: 3.eclipse中安装pydev,eclipse中help—>eclipl ...

  6. redis 的消息发布订阅

    redis支持pub/sub功能(可以用于消息服务器),这个功能类似mq,这里做一个简单的介绍 Pub/Sub Pub/Sub 从字面上理解就是发布(Publish)与订阅(Subscribe),在R ...

  7. Error:SSL peer shut down incorrectly

    从别的地方拷贝过来的项目有时会报这个错误,解决方法 File -> Project Structure -> project 对比本地项目和拷贝项目并修改至与本地项目一致

  8. 6. Adapter Class/Object(适配器)

    意图: 将一个类的接口转换成客户希望的另外一个接口.Adapter 模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作. 适用性: 你想使用一个已经存在的类,而它的接口不符合你的需求. 你想 ...

  9. linux开机启动程序

    一./etc/rc.local这是一个最简单的方法,编辑“/etc/rc.local”,把启动程序的shell命令输入进去即可(要输入命令的全路径),类似于windows下的“启动”. 使用命令 vi ...

  10. Python多线程开发简介

    Python的并发程序可以使用multiprocessing库.threading库.asyncio库.concurrent.futures库以及selectors库等等协助编写: multiproc ...