我正在使用actionmailer在rails 5.2上使用ruby,并且每当我尝试发送电子邮件时,它都将使执行过期。在Rails 3.2上这确实有效,但是Rails 5.2进行了一些更改,使邮件无法正常工作。
我已经尝试使用liver_now和deliver!解决它,但是这些命令都不起作用。我不得不注释掉#enable_starttls_auto:true,因为它到处都是错误。
开发环境:
#Google apps need to be disabled
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: "gmail.com",
authentication: "login",
#enable_starttls_auto: true,
user_name: "myusername",
password: "mypassword"
}
config.action_mailer.default_url_options = { :host => "localhost:3000" }
end
启动助手方法
elsif(type == "verify2")
name_value = params[:session][:name].downcase
email_value = params[:session][:email].downcase
subject_value = params[:session][:subject]
body_value = params[:session][:body]
@name = name_value
@email = email_value
@subject = subject_value
@body = body_value
if(name_value.empty? || email_value.empty? || subject_value.empty? || body_value.empty?)
flash[:error] = "One of the parameters was empty please ensure all are filled in."
else
UserMailer.contact(@name, @email, @subject, @body).deliver_now
flash[:success] = "Your contact info has now been sent."
end
redirect_to root_path
end
Usermailer的联系代码:
def contact(name, email, subject, body)
websiteMail = "notification@duelingpets.net"
@name = name
@email = email
@subject = subject
@body = body
mail(to: "contactduelingpets@gmail.com", from: @email, subject: "A new contact was created by #{@name}:[Duelingpets]")
end
Usermailer联系人视图
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<h1>New contact created!</h1>
<p>So this fellow <%= @name %> has taken the time to
contact the admin and provided his email
address: <%= @email %>. He has written a question
that he like to know a bit more about.
</p>
<p>Question: <%= @subject %></p>
<p>Message: <%= @body %></p>
<br>
<p>Please take the time to read over this question
and answer it in your own time. They have decided
to reach out to you.
</p>
<br>
<p>Your friend Glitchy the Dragon</p>
</body>
</html>
我希望管理员应该从发送联系方式的用户那里接收电子邮件,但是实际上,它一直在超时。