Ich habe wirklich Probleme damit. Kann jemand sehen, was hier falsch ist? Ich kann den Mailer nicht zur Arbeit bringen ... Ich versuche ein Kontaktformular auf meiner Seite zu erstellen, so dass Benutzer mir E-Mails von der Seite senden können. Ich erstelle einen "Kontakt" mit einem Namen, einer E-Mail, einem Betreff und einem Text und sende ihn dann als E-Mail.Mailer in Schienen einrichten 0_o
Controller/contacts_controller.rb
class ContactsController < ApplicationController
def index
end
def new
@contact = Contact.new
end
def create
@contact = Contact.new(contact_params)
respond_to do |format|
if @contact.save
UserMailer.mail_jill(@contact).deliver
format.html { redirect_to(@contact, :notice => 'User was successfully created.') }
else
format.html { render :action => "new" }
format.json { render :json => @contact.errors, :status => :unprocessable_entity }
end
end
end
def contact_params
params.require(:contact).permit(:name, :email, :subject, :body)
end
end
Mailer/user_mailer.rb
class UserMailer < ActionMailer::Base
def mail_jill(message)
@name = message.name
@email = message.email
@subject = message.subject
@body = message.body
mail(to: '<my_email_address>', subject: @subject, body: @body, from: @email)
end
end
views/user_mailer/mail_jill.html.erb:
<h1>From, <%= @contact.name %></h1>
<p>
@contact.body
</p>
<p>-<%= @contact.email %></p>
$ RAILS_ENV.rb:
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.sendmail_settings = {
:address => "smtp.gmail.com",
:port => "465",
:domain => "gmail.com",
:user_name => "<my_gmail_address>",
:password => "<my_gmail_password>",
:authentication => "plain",
:enable_starttls_auto => true
}
config/Umgebungen/
development.rb:
# mailer
config.active_support.deprecation = :log
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.default_url_options = { :host => "localhost:3000" }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => ENV['address'],
:port => ENV['port'],
:user_name => ENV['gmail_username'],
:password => ENV['gmail_password'],
:authentication => ENV['authentication'],
:enable_starttls_auto => true
Vollausgabefehler von der Kommandozeile nach einer E-Mail von Live-Website einreichen:
2016-04-15T23:40:12.932560+00:00 app[web.1]: Sent mail to [email protected] (348.5ms)
2016-04-15T23:40:12.932577+00:00 app[web.1]: Date: Fri, 15 Apr 2016 23:40:12 +0000
2016-04-15T23:40:12.932579+00:00 app[web.1]: From: [email protected]
2016-04-15T23:40:12.932579+00:00 app[web.1]: To: [email protected]
2016-04-15T23:40:12.932581+00:00 app[web.1]: Message-ID: <[email protected]27267.mail>
2016-04-15T23:40:12.932583+00:00 app[web.1]: Subject: hi
2016-04-15T23:40:12.932583+00:00 app[web.1]: Mime-Version: 1.0
2016-04-15T23:40:12.932584+00:00 app[web.1]: Content-Type: text/plain;
2016-04-15T23:40:12.932585+00:00 app[web.1]: charset=UTF-8
2016-04-15T23:40:12.932585+00:00 app[web.1]: Content-Transfer-Encoding: 7bit
2016-04-15T23:40:12.932586+00:00 app[web.1]:
2016-04-15T23:40:12.932587+00:00 app[web.1]: hiiiii
2016-04-15T23:40:12.932687+00:00 app[web.1]: Completed 500 Internal Server Error in 367ms
2016-04-15T23:40:12.933562+00:00 app[web.1]:
2016-04-15T23:40:12.933579+00:00 app[web.1]: Net::SMTPAuthenticationError (530-5.5.1 Authentication Required. Learn more at
2016-04-15T23:40:12.933580+00:00 app[web.1]:):
2016-04-15T23:40:12.933581+00:00 app[web.1]: app/controllers/contacts_controller.rb:12:in `create'
2016-04-15T23:40:12.933582+00:00 app[web.1]:
2016-04-15T23:40:12.933583+00:00 app[web.1]:
was genau passiert, wenn Sie versuchen, die Mail zu senden? erhalten Sie einen Fehler? – sixty4bit
@ sechzig4bit Ich habe die vollständige Fehlerausgabe hinzugefügt^ –
Ist die Portnummer korrekt? – hypern