Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encoding::UndefinedConversionError sending email with attachments #103

Open
kerby82 opened this issue Dec 11, 2017 · 1 comment
Open

Encoding::UndefinedConversionError sending email with attachments #103

kerby82 opened this issue Dec 11, 2017 · 1 comment

Comments

@kerby82
Copy link

kerby82 commented Dec 11, 2017

I'm using resque mailer to send email with a pdf attachment created on the fly.

This is the code in the controller:

 begin
        Notifier.send_contract(params[:struttura],@contract,@struttura).deliver_now
      rescue => e
        Rails.logger.error("Error  #{e.inspect} ")
      end

This is the mailer method:

	def send_contract(params,contract,struttura)

		@contract=contract
		@struttura=struttura

		[email protected]

		mail(:to => recipient, :subject => "Registrazione e Attivazione - #{struttura.nome}") do |format|
			format.html # renders send_report.text.erb for body of email
			format.pdf do
				attachments['Contratto.pdf'] = WickedPdf.new.pdf_from_string(
						render_to_string(:pdf => 'Contratto,:template => 'contracts/show.pdf.erb',locals: {:@params => params,:@contract => contract})
				)
			end
		end
	end

I'm obtaining the following error:
Errore #<Encoding::UndefinedConversionError: "\xD3" from ASCII-8BIT to UTF-8> ["/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/core_ext/object/json.rb:34:in encode'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/core_ext/object/json.rb:34:in to_json'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/core_ext/object/json.rb:34:in to_json_with_active_support_encoder'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/json/encoding.rb:57:in to_json'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/json-1.8.6/lib/json/common.rb:223:in generate'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/json-1.8.6/lib/json/common.rb:223:in generate'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/json/encoding.rb:101:in stringify'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/json/encoding.rb:35:in encode'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/json/encoding.rb:22:in encode'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/core_ext/object/json.rb:37:in to_json_with_active_support_encoder'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapters/json_common.rb:19:in dump'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/multi_json-1.12.1/lib/multi_json/adapter.rb:25:in dump'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/multi_json-1.12.1/lib/multi_json.rb:139:in dump'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/resque-1.27.4/lib/resque.rb:34:in encode'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/resque-1.27.4/lib/resque.rb:271:in push'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/resque-1.27.4/lib/resque/job.rb:95:in create'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/resque-1.27.4/lib/resque.rb:372:in enqueue_to'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/resque-1.27.4/lib/resque.rb:353:in enqueue'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/resque_mailer-2.4.3/lib/resque_mailer.rb:142:in deliver'", "/Users/acirulli/Documents/Personal/BWave/SHB/development/shb/bitbucket/shb/shb/app/controllers/strutturas_controller.rb:54:in create'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.7.1/lib/action_controller/metal/implicit_render.rb:4:in send_action'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.7.1/lib/abstract_controller/base.rb:198:in process_action'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.7.1/lib/action_controller/metal/rendering.rb:10:in process_action'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.7.1/lib/abstract_controller/callbacks.rb:20:in block in process_action'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/callbacks.rb:117:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/callbacks.rb:555:in block (2 levels) in compile'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/callbacks.rb:505:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/callbacks.rb:92:in __run_callbacks__'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/callbacks.rb:778:in _run_process_action_callbacks'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/callbacks.rb:81:in run_callbacks'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.7.1/lib/abstract_controller/callbacks.rb:19:in process_action'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.7.1/lib/action_controller/metal/rescue.rb:29:in process_action'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.7.1/lib/action_controller/metal/instrumentation.rb:32:in block in process_action'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/notifications.rb:164:in block in instrument'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/notifications/instrumenter.rb:20:in instrument'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/notifications.rb:164:in instrument'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.7.1/lib/action_controller/metal/instrumentation.rb:30:in process_action'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.7.1/lib/action_controller/metal/params_wrapper.rb:250:in process_action'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.7.1/lib/abstract_controller/base.rb:137:in process'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/actionview-4.2.7.1/lib/action_view/rendering.rb:30:in process'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.7.1/lib/action_controller/metal.rb:196:in dispatch'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.7.1/lib/action_controller/metal/rack_delegation.rb:13:in dispatch'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.7.1/lib/action_controller/metal.rb:237:in block in action'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.7.1/lib/action_dispatch/routing/route_set.rb:74:in dispatch'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.7.1/lib/action_dispatch/routing/route_set.rb:43:in serve'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.7.1/lib/action_dispatch/journey/router.rb:43:in block in serve'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.7.1/lib/action_dispatch/journey/router.rb:30:in each'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.7.1/lib/action_dispatch/journey/router.rb:30:in serve'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.7.1/lib/action_dispatch/routing/route_set.rb:817:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/newrelic_rpm-4.2.0.334/lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/omniauth-1.4.0/lib/omniauth/strategy.rb:186:in call!'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/omniauth-1.4.0/lib/omniauth/strategy.rb:164:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/newrelic_rpm-4.2.0.334/lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/omniauth-1.4.0/lib/omniauth/strategy.rb:186:in call!'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/omniauth-1.4.0/lib/omniauth/strategy.rb:164:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/newrelic_rpm-4.2.0.334/lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/newrelic_rpm-4.2.0.334/lib/new_relic/rack/agent_hooks.rb:30:in traced_call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/newrelic_rpm-4.2.0.334/lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/newrelic_rpm-4.2.0.334/lib/new_relic/rack/browser_monitoring.rb:32:in traced_call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/newrelic_rpm-4.2.0.334/lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/warden-1.2.7/lib/warden/manager.rb:36:in block in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/warden-1.2.7/lib/warden/manager.rb:35:in catch'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/warden-1.2.7/lib/warden/manager.rb:35:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/newrelic_rpm-4.2.0.334/lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/rack-1.6.8/lib/rack/etag.rb:24:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/newrelic_rpm-4.2.0.334/lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/rack-1.6.8/lib/rack/conditionalget.rb:38:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/newrelic_rpm-4.2.0.334/lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/rack-1.6.8/lib/rack/head.rb:13:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/newrelic_rpm-4.2.0.334/lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/remotipart-1.3.1/lib/remotipart/middleware.rb:32:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/newrelic_rpm-4.2.0.334/lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.7.1/lib/action_dispatch/middleware/params_parser.rb:27:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/newrelic_rpm-4.2.0.334/lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.7.1/lib/action_dispatch/middleware/flash.rb:260:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/newrelic_rpm-4.2.0.334/lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/rack-1.6.8/lib/rack/session/abstract/id.rb:225:in context'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/rack-1.6.8/lib/rack/session/abstract/id.rb:220:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/newrelic_rpm-4.2.0.334/lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.7.1/lib/action_dispatch/middleware/cookies.rb:560:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/newrelic_rpm-4.2.0.334/lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.7.1/lib/action_dispatch/middleware/callbacks.rb:29:in block in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/callbacks.rb:88:in run_callbacks'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/callbacks.rb:778:in _run_call_callbacks'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/callbacks.rb:81:in run_callbacks'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.7.1/lib/action_dispatch/middleware/callbacks.rb:27:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/newrelic_rpm-4.2.0.334/lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.7.1/lib/action_dispatch/middleware/reloader.rb:73:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/newrelic_rpm-4.2.0.334/lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.7.1/lib/action_dispatch/middleware/remote_ip.rb:78:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/newrelic_rpm-4.2.0.334/lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.7.1/lib/action_dispatch/middleware/debug_exceptions.rb:17:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/newrelic_rpm-4.2.0.334/lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.7.1/lib/action_dispatch/middleware/show_exceptions.rb:30:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/newrelic_rpm-4.2.0.334/lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/railties-4.2.7.1/lib/rails/rack/logger.rb:38:in call_app'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/railties-4.2.7.1/lib/rails/rack/logger.rb:20:in block in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/tagged_logging.rb:68:in block in tagged'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/tagged_logging.rb:26:in tagged'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/tagged_logging.rb:68:in tagged'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/railties-4.2.7.1/lib/rails/rack/logger.rb:20:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/newrelic_rpm-4.2.0.334/lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.7.1/lib/action_dispatch/middleware/request_id.rb:21:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/newrelic_rpm-4.2.0.334/lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/rack-1.6.8/lib/rack/methodoverride.rb:22:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/newrelic_rpm-4.2.0.334/lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/rack-1.6.8/lib/rack/runtime.rb:18:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/newrelic_rpm-4.2.0.334/lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.7.1/lib/active_support/cache/strategy/local_cache_middleware.rb:28:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/newrelic_rpm-4.2.0.334/lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/rack-1.6.8/lib/rack/lock.rb:17:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/newrelic_rpm-4.2.0.334/lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/actionpack-4.2.7.1/lib/action_dispatch/middleware/static.rb:120:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/newrelic_rpm-4.2.0.334/lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/rack-1.6.8/lib/rack/sendfile.rb:113:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/newrelic_rpm-4.2.0.334/lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/railties-4.2.7.1/lib/rails/engine.rb:518:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/railties-4.2.7.1/lib/rails/application.rb:165:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/newrelic_rpm-4.2.0.334/lib/new_relic/agent/instrumentation/middleware_tracing.rb:92:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/rack-1.6.8/lib/rack/lock.rb:17:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/rack-1.6.8/lib/rack/content_length.rb:15:in call'", "/Users/acirulli/.rvm/gems/ruby-2.3.0/gems/rack-1.6.8/lib/rack/handler/webrick.rb:88:in service'", "/Users/acirulli/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/webrick/httpserver.rb:140:in service'", "/Users/acirulli/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/webrick/httpserver.rb:96:in run'", "/Users/acirulli/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/webrick/server.rb:296:in block in start_thread'"]`

Everything is working just fine for other email that don't include pdf.

@zapnap
Copy link
Owner

zapnap commented Dec 17, 2017

And presumably this works fine if you yank ResqueMailer from your mailer? If so, can you post a simple example project and I'll try to find time to take a look? txx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants