我建立了一个非常基本的联系表,允许人们向我发送电子邮件。这对我来说只是学习的一部分,因此它不是生产站点。当用户输入他们的信息并单击“发送”按钮时,它似乎经历了几秒钟到一分钟后,我得到以下回弹。
code_1 | 0-0 worker error { name: 'unknown error',
code_1 | message:
code_1 | 'unknown error: cannot find Chrome binary\n (Driver info: chromedriver=2.43.600233
我的代码似乎是正确的,并且我认为问题出在smtp设置之内,有人可以确认吗?我正在通过Godaddy使用Office365,我看到很多人都在努力使其正常工作。
message_mailer.rb
Net::SMTPFatalError (554 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException
.MapiExceptionSendAsDenied; Failed to process message due to a permanent
exception with message Cannot submit message. 16.55847:6D0F0000,
17.43559:0000000004020000000000000100000000000000,
20.52176:140FC3870D00F01FCB030000, 20.50032:140FC3877D17401080030400,
0.35180:D0030000, 255.23226:0A007680, 255.27962:0A000000,
255.27962:0E000000, 255.31418:1F000130, 16.55847:A6000000,
17.43559:00000000E0020000000000000100000000000000,
20.52176:140FC3870D00401080030400, 20.50032:140FC3877D1710103A000000,
0.35180:03000136, 255.23226:21000000, 255.27962:0A000000,
255.27962:32000000, 255.17082:DC040000, 0.27745:44000000,
4.21921:DC040000, 255.27962:FA000000, 255.1494:49000000, 0.38698:00000000,
0.37692:1A010480, 0.37948:00000600, 5.33852:00000000534D545000010480,
4.56248:DC040000, 7.40748:010000000000010B31333A4D,
7.57132:00000000000000003A343731, 1.63016:32000000, 4.39640:DC040000,
8.45434:2653E8C6336A0D409107BFF092BEB44600000000,
5.10786:0000000031352E32302E313938372E3031333A4D5748505231374D42313433383A3437
3161356633312D326662322D346661312D383035372D3464363739346338313461300040101A010480, 255.1750:9D000000, 255.31418:80000000, 0.22753:03000236,
255.21817:DC040000, 4.60547:DC040000, 0.21966:03001736, 4.30158:DC040000
[Hostname=MWHPR17MB1438.namprd17.prod.outlook.com]
):
app/controllers/messages_controller.rb:11:in `create'
messages_controller.rb
class MessageMailer < ApplicationMailer
default from: ENV['SMTP_EMAIL']
# Subject can be set in your I18n file at config/locales/en.yml
# with the following lookup:
#
# en.message_mailer.contact_me.subject
#
def contact_me(message)
@body = message.message_body
mail to: ENV['SMTP_EMAIL'], from: message.email_address
end
end
message.rb
class MessagesController < ApplicationController
def new
@message = Message.new
end
def create
@message = Message.new(message_params)
if @message.valid?
MessageMailer.contact_me(@message).deliver_now
redirect_to new_message_url, notice: "Message received"
else
render :new
end
end
private
def message_params
params.require(:message).permit(:name, :email_address, :message_body)
end
end
app / views / messages / new.html.erb
class Message
include ActiveModel::Model
attr_accessor :name, :email_address, :message_body
validates :name, :email_address, :message_body, presence: true
end
config / environments / development.rb
<%= form_for @message, url: create_message_url do |f| %>
<%= notice %>
<%= @message.errors.full_messages.join(', ') %>
<%= f.text_field :name, placeholder: 'Name' %>
<%= f.email_field :email_address, placeholder: 'Email address' %>
<%= f.text_area :message_body, placeholder: 'body' %>
<%= f.submit 'Send' %>
答案 0 :(得分:0)
我通过进行以下更改解决了该问题,并且在计时器计时结束后将接受此答案!
/config/environment.rb
# Load the Rails application.
require_relative 'application'
ActionMailer::Base.delivery_method = :sendmail # Added this line
ActionMailer::Base.smtp_settings = { # Added this line
:domain => 'localhost' # Added this line
} # Added this line
# Initialize the Rails application.
Rails.application.initialize!
/config/environments/development.rb
config.action_mailer.perform_caching = false
config.action_mailer.default_url_options = {
:host => "localhost" # Removed port
}
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.smtp_settings = {
:address => 'smtp.office365.com',
:port => 587,
:domain => 'localhost', # Added domain and set to localhost
:authentication => :login,
:user_name => ENV['SMTP_EMAIL'],
:password => ENV['SMTP_PASS'],
:enable_starttls_auto => true
}