我試圖創建一個簡單的博客(使用rails 5),並希望發送電子郵件更新時,當我發佈新的東西的用戶。我試圖使用actionmailer,我正在使用設計來註冊用戶。我試圖在第一個用戶開始時進行設置。動作郵件不發送/接收電子郵件5
當我看着我的本地服務器的電子郵件似乎是發送,但它沒有收到。任何建議將非常歡迎我一直卡住了一段時間。
UserNotifierMailer#sample_email: processed outbound mail in 410.4ms
Sent mail to [email protected] (853.2ms)
Date: Wed, 27 Jul 2016 12:05:33 +0100
From: [email protected]
To:[email protected]
Message-ID: <[email protected]me.mail>
Subject: Sample Email
Mime-Version: 1.0
Content-Type: multipart/alternative;
boundary="--==_mimepart_5798957d951e2_ae813ff962abfe1466312";
charset=UTF-8
Content-Transfer-Encoding: 7bit
我的帖子控制器看起來是這樣的:
def create
@user = User.first
@post = current_user.posts.build(post_params)
if @post.save
flash[:success] = "Your post has been created!"
UserNotifierMailer.sample_email(@user).deliver
redirect_to posts_path
else
flash[:alert] = "Your new post couldn't be created! Please check the form."
render :new
end
end
我的郵件看起來是這樣的:
class UserNotifierMailer < ApplicationMailer
default from: "[email protected]"
def sample_email(user)
@user = user
@url = 'http://www.google.com'
mail(to: @user.email, subject: 'Sample Email')
end
end
,在我development.rb我有以下設置:
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: "gmail.com",
authentication: "plain",
enable_starttls_auto: true,
user_name: "my_gmail_username",
password: "my_gmail_password"
}
試着改變對你的谷歌帳戶此功能(不知道這是否會幫助):https://www.google。 com /設置/安全/ lesssecureapps – Deep
我終於得到它的工作,這是谷歌2步驗證。確保它已關閉! –