Send mail in app sintra ruby

0

Well I have the following form in my index view

<form action="/mailcontacto" method="post">
            <div class="jx-ticket-first-name">
            <input type="text" id="reg_name" name="reg_name" placeholder="Nombre" class="jx-form-text" />
            </div>
        <div class="jx-ticket-phone">
        <input type="text" id="reg_empresa" name="reg_empresa" placeholder="Institución" class="jx-form-text" />
        </div>
            <div class="jx-ticket-email">
            <input type="text" id="reg_email" name="reg_email" placeholder="Email" class="jx-form-text" data-validation-length="email" data-validation="required"/>
            </div>
        <input type="hidden" id="reg_subject" name="reg_subject" placeholder="Número Telefónico" class="jx-form-text" />
            <div class="jx-ticket-phone">
            <input type="text" id="reg_phone" name="reg_phone" placeholder="Número Telefónico" class="jx-form-text" />
            </div>
        <div class="jx-ticket-phone">
            <input type="text" id="reg_mensaje" name="reg_mensaje" placeholder="Mensaje" class="jx-form-text" />
            </div>
            <input type="submit" id="submit-register-9" name="submit-register-9" class="jx-form-btn jx-btn-default" value="send" placeholder="Enviar" />
            </form>

Which sends me to the view / is / mail contact that I have created in my app.rb (main) which I defined it as follows:

post '/es/mailcontacto' do
  require 'pony'

  from = "[email protected]"
  subject = "Solicitud de información o demo"

  Pony.mail(
    :from => from,
    :subject => subject,
    :headers => { 'Content-Type' => 'text/html' },
    :body => erb(:"/mail"),
    :to => 'para',
    :via => :smtp,
    :via_options => {
    :address              => 'smtp.gmail.com',
    :port                 => '587',
    :enable_starttls_auto => true,
    :user_name            => 'usuario',
    :password             => 'contraseña',
    :authentication       => :plain, # :plain, :login, :cram_md5, no auth by default
    :domain               => "dominio"
      })
  redirect '/'
end

Then the body of the mail I have it in another view where I call the values of the form which is called mail.erb and it contains the following:

<p><%= "Nombre: #{params[:reg_name]}" %></p>
<p><%= "Emepresa: #{params[:reg_empresa]}" %></p>
<p><%= "Email: #{params[:reg_email]}" %></p>
<p><%= "Telefono: #{params[:reg_phone]}" %></p>
<p><%= "Asunto: #{params[:reg_subject]}" %></p>
<p><%= "Mensaje: #{params[:reg_mesaje]}" %></p>

From what I understand the error is that when you hit the send button does not really send me to the view is / mailcontacto, I mark an error of Internal Server, I can not decipher what is happening, I do not know much about Sinatra, I hope someone could help me.

    
asked by Jerry Jiménez 19.08.2017 в 22:02
source

1 answer

0
  • Verify that you have the permissions in google to be able to send the emails from your application (you can do it in this link ).

  • Change the value of :authentication to :login :

  • :authentication => :login
    
        
    answered by 23.08.2017 в 01:48