Giter Club home page Giter Club logo

mail_form's People

Contributors

aried3r avatar boutvalentin avatar brchristian avatar bregor avatar carlosantoniodasilva avatar danascheider avatar dependabot[bot] avatar georgeguimaraes avatar hugobarauna avatar josevalim avatar lucasmazza avatar matiaskorhonen avatar mracos avatar nashby avatar nicolasleger avatar oponder avatar petergoldstein avatar rafaelfranca avatar robin850 avatar rubypirate avatar serho avatar sporkd avatar stuwil avatar tegon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mail_form's Issues

ORM example should include MailForm::Shim

Hello. I couldn't get mail_form to work with my ActiveRecord object until I also included MailForm::Shim. Otherwise it still sends the email, but none of the model attributes get printed (only the appends).

So in the README needs:

class User < ActiveRecord::Base
  include MailForm::Delivery
  include MailForm::Shim

instead of just:

class User < ActiveRecord::Base
    include MailForm::Delivery

Peter

undefined method `true' for

I am relatively new in Ruby on Rails programming, and I got this error when trying to use the mail_form gem. The error is in the create function as can be seen:

captura de pantalla 2015-12-23 a la s 2 31 46 a m

I think I got all setup the correct way:

My model is like this:

class Contact < MailForm::Base
      attribute :name,        :validate => :true
      attribute :email,       :validate => /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i
      attribute :message,     :validate => :true
      attribute :nickname,    :captcha => :true

     def headers
     {
       :subject => "Contact Form",
       :to => "(my email)",
       :from => %("#{name}" <#{email}>)
      }
     end
end

I don't know if matters that I'm trying to create a site with only one page, so I have the form to create a new contact in the welcome.html.erb of the pages controller, but I am defining the contact:

def welcome
   @admin = Admin.find(1)
   @projects = Project.all.order('created_at DESC')
   @contact = Contact.new
end

Also I think that matters, that the create function (that is throwing the error) is in the contacts controller, I don't know if there was ok or it will be better at the same controller as the Contact.new (in the welcome function of pages):

def create
    @contact = Contact.new(params[:contact])
    @contact.request = request
    if @contact.deliver
      redirect_to(root_path, :notice => "Thank you for contacting me. I will reply shortly!")
    else
      flash.now[:error] = 'Cannot send message.'
    end
 end

I have tested in production and in development and in the both happen the same error. I am following this tutorial of Mackenzie Child and this didn't happen to him, and we have the same code(except for the fact that I am trying to make this in only one view). I don't know if it helps, but this is what I have in my config/environments/development.rb:

  config.action_mailer.delivery_method = :letter_opener

So in development I'm using the gem letter_opener for displaying the messages instead of sending mails, although this affects nothing in the error because the error was showing up way before I installed the gem.

And in production I use sendgrid addon from heroku:

 config.action_mailer.default_url_options = { host: 'http://www.luisbarajasp.com' }
 config.action_mailer.delivery_method = :smtp

 ActionMailer::Base.smtp_settings = {
     :address        => 'smtp.sendgrid.net',
     :port           => '587',
     :authentication => :plain,
     :user_name      => ENV['SENDGRID_USERNAME'],
     :password       => ENV['SENDGRID_PASSWORD'],
     :domain         => 'heroku.com',
     :enable_starttls_auto => true
  }

I have searched in many places and in all the questions on stack overflow but I found nothing. If you can help me that would be greate.

Thanks.

Net::SMTPAuthenticationError

Hello guys I had my setup working well after a time I have this error:

Completed 500 Internal Server Error in 892ms (ActiveRecord: 0.0ms | Allocations: 19634)
Net::SMTPAuthenticationError (530-5.7.0 Authentication Required. Learn more at
):

Somebody can solve it?

Update for Rails 5

Can you tell me if this gem will be updated to work with Rails 5. It currently works but is causing some issues, I believe because it injects relationships on ActiveRecord::Base rather than ApplicationRecord.

Undefined method `before_deliver` when included

Hi there -

Following the instructions on the readme, I added include MailForm::Delivery on an existing class I had. I then received undefined method `before_deliver' when running my tests. I eventually solved it by also adding include MailForm::Shim. I'm not sure if that's the "right" way to do it, but I figured I'd post here in case 1: Someone else has this issue; 2: It's the wrong way and you can correct me; or 3: It can be added to the README

Change date format?

Hi and thanks for a great gem! Fantastic work.

I'm stuck on day 2 having problems changing the format of the date - can you help me out so it doesn't output as 2017-19-02 but 02-19-2017? - maybe it's really simple, but I've googled a lot with no luck and read the documentation

I have this in my contact.rb:
attribute :birthdaydate

And in my view:
<%= f.date_field :birthdaydate, value: 30.days.from_now.to_date.to_s, :as => :text %>

I've tried putting this in my config/locales/en.yml:


en:
  date:
    formats:
      default: "%d/%m/%Y"
  time:
    formats:
      default: "%d/%m/%Y %H:%M"

But I can't seem to change the output. Any help would be greatly appreciated!

Docs and `mail_attachments`

Hey, it took me a while to work out why attachments were not being attached.

I had read the docs, but there was no mention of having to define mail_attachments on the form class. In the example where you mention attachments it would be good to mention that the following is also required (I only happened to find it by code diving and throwing byebugs in the gem):

class Form < Mailer::Base

     attributes :image, validate: true, attactment: true

     def mail_attachments
         [:image]
     end
end

link_to not working (URI::InvalidComponentError)

When I tried to place a link in the view I got this error:

URI::InvalidComponentError in VendorContactFormsController#create

bad component(expected host component): localhost:3000

When i replace localhost:3000 in action_mailer.default_url_options with host (which of course makes no sense..) the error disappears.

Is link_to not supported in mail_form?

How do I send an email with attachment?

I'm trying to send an email with attachment but it's not working.

In the form, I used:

<%= simple_form_for @comprovante, html: { multipart: true }, defaults: { wrapper_html: { class: 'form-group' }, input_html: { class: 'form-control' } } do |f| %>

 <%= f.file_field :file %>

<% end %>

I receive the email but there is nothing attached.

Email`s Body
Name: John
Email: [email protected]
Message: Testing email
File: #ActionDispatch::Http::UploadedFile:0x00007fc9094557c0

mail encoding

Hi,
I don't know if it is a bug, but I dont manage it to get a proper utf-8 encoding.
special chars like ü or éà are not properly encoded.

Do you have any idea? Because in the documentation is written, that it should be utf-8 standard encoding though.

thnx a lot, greetinx

This is the result of the mailing:

Subject:
Kontakt_=9Fber_itoolz=2Ech

Body:
Kontakt ƒber itoolz.ch
Vorname: Rafael
Nachname: Schär

EOFError (end of file reached): app/controllers/contacts_controller.rb:5:in `create'

Hi,

I´m using mail_form in a staging environment and I´m having this error:

<br />  
Oct 22 07:27:47 XXXXXX-stagging app/web.1:  ----==_mimepart_580b776152614_73fbd91d1333045d2--  
Oct 22 07:27:47 XXXXXX-stagging app/web.1:  Completed 500 Internal Server Error in 5384ms 
Oct 22 07:27:47 XXXXXX-stagging app/web.1:  EOFError (end of file reached): 
Oct 22 07:27:47 XXXXXX-stagging app/web.1:    app/controllers/contacts_controller.rb:5:in `create' 

In my staging.rb I have this SMTP configuration:

config.action_mailer.raise_delivery_errors = true
    config.action_mailer.perform_deliveries = true
    config.action_mailer.asset_host = "https://XXXXXXXXX-stagging.herokuapp.com"
    config.action_mailer.default_url_options = { :host =>  ENV['HOST_PRO']}
    # Action Mailer
    config.action_mailer.smtp_settings = {
      :address              => "smtp.zoho.com",
      :port                 => 465,
      :user_name            => ENV['ZOHO_USERNAME_PRO'],
      :password             => ENV['ZOHO_PASSWORD_PRO'],
      :authentication       => :login,
      :ssl                  => true,
      :tls                  => true
    }

I´m using this ZOHO_USERNAME_PRO as the :to email in contacts.rb

# Declare the e-mail headers. It accepts anything the mail method
  # in ActionMailer accepts.
  def headers
    {
      :subject => "Consulta de #{nombre} - #{email}",
      :to => "[email protected]",
      :from => %("#{nombre}" <#{email}>)
    }
  end

My app is Rails 4.0.2 and fails on Heroku and the rest of mails works fine.

Thanks for any help

Ability to modify smtp settings such as openssl_verify_mode

I have an application that is leveraging the mail_form gem. Does the gem offer the ability to customize the smtp settings at all?

For example here is an error that I get when sending through my postfix service on localhost.

F, [2014-11-20T02:19:11.767423 #15622] FATAL -- : 
OpenSSL::SSL::SSLError (hostname "localhost" does not match the server certificate):
  app/controllers/contact_controller.rb:15:in `create'

I'm thinking that if I could simply pass in an argument like below that it might solve my issues:

:openssl_verify_mode  => 'none'

Any insight would be appreciated.

undefined method `create'

Rails-3.0.3
Active record

class SupportMailer < MailForm::Base

  attribute :name,      :validate => true
  attribute :email,     :validate => /[^@]+@[^\.]+\.[\w\.\-]+/

  attribute :message
  attribute :nickname,  :captcha  => true

  def headers
    { :to => "[email protected]",
      :from => %("#{name}" <#{email}>)
    }
  end
end

In rails console:
> m = SupportMailer.new(:email => "[email protected]", :name => "Silly user")

> m.create
NoMethodError: undefined method `create' for #<SupportMailer:0x1039f65b0>

form validation

Hi,

The gem is really good though I ran into some problems (I am sort of a beginner in rails) when validating form. I had a hard time finding why my create function with @contact = Contact.new(params[:contact]).deliver always returned Nil object. In SO I was pointed out that ActiveRecord validations are only called on methods like save or valid? so I have to add a conditional statement for everything to work.

This should be a good this to add in your docs or make the deliver method call the ActiveRecord validations in future releases.

Hope it helps.

Warning / syntax error during deploy to heroku

Hey there, can these be a problem?

gemspec line 10:

  s.description = %q{{Send e-mail straight from forms in Rails with I18n, validations, attachments and request information.}

During deploy to heroku I'm getting this message:

WARNING: vendor/bundle/ruby/1.9.1/specifications/mail_form-1.4.0.gemspec:10: unterminated string meets end of file
vendor/bundle/ruby/1.9.1/specifications/mail_form-1.4.0.gemspec:10: syntax error, unexpected $end, expecting keyword_end
WARNING: # -- encoding: utf-8 --

Gem::Specification.new do |s|
  s.name = %q{mail_form}
  s.version = "1.4.0"

  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
  s.authors = ["José Valim", "Carlos Antônio"]
  s.date = %q{2012-12-13}
  s.description = %q{{Send e-mail straight from forms in Rails with I18n, validations, attachments and request information.}
  s.email = %q{[email protected]}
  s.files = ["CHANGELOG", "MIT-LICENSE", "README.md", "lib/generators/rails/mail_form_generator.rb", "lib/generators/rails/templates/model.rb", "lib/mail_form/base.rb", "lib/mail_form/delivery.rb", "lib/mail_form/notifier.rb", "lib/mail_form/shim.rb", "lib/mail_form/version.rb", "lib/mail_form/views/mail_form/contact.erb", "lib/mail_form.rb", "test/mail_form_test.rb", "test/resource_test.rb", "test/test_file.txt", "test/test_helper.rb", "test/views/mail_form/custom_template.erb"]
  s.homepage = %q{https://github.com/plataformatec/mail_form}
  s.require_paths = ["lib"]
  s.rubyforge_project = %q{mail_form}
  s.rubygems_version = %q{1.3.7}
  s.summary = %q{Send e-mail straight from forms in Rails with I18n, validations, attachments and request information.}
  s.test_files = ["test/mail_form_test.rb", "test/resource_test.rb", "test/test_file.txt", "test/test_helper.rb", "test/views/mail_form/custom_template.erb"]

  if s.respond_to? :specification_version then
    current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
    s.specification_version = 3

    if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
      s.add_runtime_dependency(%q<actionmailer>, ["~> 3.0"])
    else
      s.add_dependency(%q<actionmailer>, ["~> 3.0"])
    end
  else
    s.add_dependency(%q<actionmailer>, ["~> 3.0"])
  end
end

MailForm Instance does not respond to create

I will let the console speak for itself:

c = ContactMailer.new(:name => 'n', :email => '4', :message => 'e' )
=> #<ContactMailer:0x10318f570 @name="n", @email="4", @message="e">

c.create
NoMethodError: undefined method `create' for #<ContactMailer:0x10318f570 @name="n", @email="4", @message="e">
from (irb):2

Here is app/mailers/contact_mailer.rb:

class ContactMailer < MailForm::Base
  attributes :name,    :validate => true
  attributes :email,   :validate => /[^@]+@[^\.]+\.[\w\.\-]+/
  attributes :message, :validate => true

  def headers
    {
      :subject => "Contact From Us",
      :to => "[email protected]",
      :from => %("#{name}" <#{email}>)
    }
  end
end

charset error

I'm getting a charset error when I'm submitting my form. Also using SendGrid service.

NoMethodError (undefined method `charset=' for #SendGrid::Mail:0x00007fa822849ed8):

SMTP in production env:

  config.action_mailer.default_url_options = { host: "http://www.app.com" } # needs to be changed to domain
  config.action_mailer.delivery_method     = :smtp
  ActionMailer::Base.smtp_settings= {
    :user_name => ENV['SENDGRID_USERNAME'],
    :password => ENV['SENDGRID_PASSWORD'],
    :domain => 'http://www.a.com',pp
    :address => 'smtp.sendgrid.net',
    :port => '465',
    :authentication => :plain,
    :enable_starttls_auto => true
  }

controller:

  def new
    @contact = Contact.new
    @markers = [ {lat: 10.967460, lng: -74.781980}]
  end

  def create
    @contact = Contact.new(params[:contact])
    @contact.request = request
    respond_to do |format|
      if @contact.deliver
        flash.now[:error] = nil
        redirect_to root_path, notice: 'Message sent successfully'
      else
        flash.now[:error] = 'Cannot send message'
        render :new
      end
    end
  end

Multiple forms

Hello,

I am trying to get multiple forms to use different view templates. However because each of my form inherits from MailForm::Base which in turn calls MailForm::Notifier.contact() when the deliver! meh, when rails comes to guess the template, it uses the contact template.

I am probably missing something, however because of the abstraction, I cannot see a way to use multiple view templates for the emails.

Thank you in advance for any help you can provide.

deliver_now ?

Any plans to update this to use deliver_now in rails 4?

adding headers

Hi...

I'm trying to edit the headers of a ContactForm in order to add a :cc field if the user want a copy of the mail...

Here is my snippet:

  def create
    begin
      @contact_form = ContactForm.new(params[:contact_form])
      @contact_form.headers.merge!({:cc => params[:contact_form][:email]}) if params[:send_me_copy]
      @contact_form.request = request
      if @contact_form.deliver
...

But I don't see the :cc field in the headers... Where I'm missing something?
Thank you so much in advance...

License missing from gemspec

RubyGems.org doesn't report a license for your gem. This is because it is not specified in the gemspec of your last release.

via e.g.

spec.license = 'MIT'
# or
spec.licenses = ['MIT', 'GPL-2']

Including a license in your gemspec is an easy way for rubygems.org and other tools to check how your gem is licensed. As you can imagine, scanning your repository for a LICENSE file or parsing the README, and then attempting to identify the license or licenses is much more difficult and more error prone. So, even for projects that already specify a license, including a license in your gemspec is a good practice. See, for example, how rubygems.org uses the gemspec to display the rails gem license.

There is even a License Finder gem to help companies/individuals ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough issue that even Bundler now generates gems with a default 'MIT' license.

I hope you'll consider specifying a license in your gemspec. If not, please just close the issue with a nice message. In either case, I'll follow up. Thanks for your time!

Appendix:

If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), GitHub has created a license picker tool. Code without a license specified defaults to 'All rights reserved'-- denying others all rights to use of the code.
Here's a list of the license names I've found and their frequencies

p.s. In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :). See the previous link or my blog post about this project for more information.

Is this working for Rails 5.1?

It's not working in production, so I'm not getting the email, plus I get a 500 server error. That Errno::EADDRNOTAVAIL and cannot access request email on port 25...

delayed deliver / sidekiq

Hello,
Is there any way to use this gem with a sidekiq worker ?
(as with the deliver_later method with Devise gem)

Custom templates

Hi guys,

The README says that it's possible to specify your own custom template for the notifier, but I'm not sure how exactly that can be done given that the notifier's template_root is set to lib/../views and it seems to be trying to load templates from there.

I guess it's possible to specify a relative path as a workaround if you have mail_form installed as a plugin, but in case of gem it won't work.

I wonder if I'm missing something and if you guys use this feature yourself.

Thanks!

rails 4 with MailForm undefined method `_run_deliver_callbacks'

I have installed the MailForm gem and set up Mailcatcher. You can see my code at https://github.com/kfn8dkodemonkey/HireMe the site is at www.kaffeinatedkodemonkey.com. When I click Services button (bottom of page) and then click on a service and then on Request Meeting button and submit the form I receive this error, "undefined method `_run_deliver_callbacks' for #SendMail:0x0000000481bc68".

In searching for a fix I found your post that says it is fixed. I am replying to your post / fix because I am unable to find where I have gone wrong or if maybe I have found another issue.

Error when using a date attribute with date_select

Hi,

I defined a class ApplicationRequest < MailFrom with an attribute :birthdate.

class ApplicationRequest < MailForm::Base
attribute :birthdate, :validate => true
.
.
.
end

In my views, I use a date_select helper:
<%= f.date_select :birthdate %>

When I submit the form I get following Exception:
NoMethodError in Application requestsController#create

undefined method `birthdate(1i)=' for #<ApplicationRequest:0xa43a1fc @firstname="", @lastname="">

Shouldn't mail form handle this form me? If not, how should I handle the date the right way?

Cheers,

Roberto

P.S.: Greeeeat gem, you've written there!

Email templates

Is there a way to have multiple template? Following your doc, I can create a template using a file in mail_form/contact.erb but apparently I can not create a second template... Is there an easy way to do so?

How to make it working with sidekiq worker?

Is it possible to make this gem working async as a sidekiq worker?

I got this error
2015-07-24T12:35:26.451Z 1877 TID-ovhe84764 WARN: NoMethodError: private method new' called for ContactWorker:Class`

Rails 6 support

Is this gem still maintained and is support for rails 6 planned?

delayed_job_active_record

Hi,

Please can you show me how to use delayed_job_active_record with this awesome gem?

I am not sure how to wire it up as the document for delayed job says:

# without delayed_job
Notifier.signup(@user).deliver

# with delayed_job
Notifier.delay.signup(@user)

So, we should not call deliver directly, but then I am not sure how to use this library with delayed job effectively, ideas?

I tried this:

class ContactFormController < ApplicationController
  def new
    @contact_form = ContactForm.new 
  end

  def create
    @contact_form = ContactForm.new(params[:contact_form]) 
    @contact_form.request = request
    @contact_form.delay.deliver
    flash.now[:notice] = 'Thank you for your message!' 
  end 
end

but got this error:
Jobs cannot be created for records before they've been persisted

Spam check not working in test/production?

As far as I can tell, at the moment the spam check works properly in development (raising an error), but forms will deliver as normal even if a captcha field is populated in other environments.

This wasn't the case in an older project running 1.5.1, but is the case in 1.6.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.