I try to test schema integration with rails application. I used my personal Gmail account to configure SMTP :
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'gmail.com',
user_name: 'XXXX#gmail.com',
password: 'XXXX',
authentication: 'plain',
enable_starttls_auto: true
}
I test to send it to my own account. But it's seems that doesn't work..
I test with example code from :
PS : The mail pass validation
Thank you
EDIT : Header of my mail
Return-Path: <XXX#gmail.com>
Received: from gmail.com (84-74-24-22.dclient.hispeed.ch. [84.74.24.22])
by mx.google.com with ESMTPSA id m8sm9364668eeg.11.2014.04.23.13.34.35
for <XXX#gmail.com>
(version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
Wed, 23 Apr 2014 13:34:35 -0700 (PDT)
Date: Wed, 23 Apr 2014 22:34:34 +0200
From: XXX#gmail.com
To: XXX#gmail.com
Message-ID: <535823da92e7c_3d223ffc2442dbe093598#WS-39.local.mail>
Subject: =?UTF-8?Q?Merci_d'avoir_command=C3=A9_!?=
Mime-Version: 1.0
Content-Type: multipart/alternative;
boundary="--==_mimepart_535823da916a1_3d223ffc2442dbe0934a9";
charset=UTF-8
Content-Transfer-Encoding: 7bit
I have a functionality wherein i have to upload a large number of records from a csv file. If any one of the records is invalid, no data should be uploaded. A csv file with errors against the invalid records needs to be sent to the user who uploaded the data. I am using rails (3.2), sidekiq (2.16.1) and mysql.
All the mails (devise and custom) mails are delivered and i receive them in my gmail inbox. The above functionality worked fine before being shifted to sidekiq.
User model
#works n gets delivered in inbox
Notifier.send_welcome_mail(self).deliver
Sidekiq Worker
class UploadWorker
include Sidekiq::Worker
sidekiq_options retry: false
def perform(user_id, inspection_id)
user = User.find(user_id)
inspection = Inspection.find(inspection_id)
err = false
#check if all data is valid and upload if valid
#
...
#shows in development log but doesnt get delivered in inbox.
Notifier.delay.upload_success(user, inspection) if err
Notifier.delay.upload_failed(user, inspection) unless err
end
end
development log
Sent mail to someone#gmail.com (142ms)
Date: Wed, 13 Nov 2013 17:24:25 +0530
To: someone#gmail.com
Message-ID: <5283687179a92_203f59f273e3#gmail.mail>
Subject: ["someone#gmail.com"] Upload failed
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
sidekiq log
2013-11-13T13:21:20Z 10064 TID-1n41gu UploadWorker JID-2d2c930601caf6a62c86e142 INFO: start
2013-11-13T13:22:13Z 10064 TID-1n41gu UploadWorker JID-2d2c930601caf6a62c86e142 INFO: done: 52.858 sec
2013-11-13T13:22:13Z 10064 TID-1w7iwu Sidekiq::Extensions::DelayedMailer JID-bcae8ea4974ecfe280e411bd INFO: start
2013-11-13T13:22:14Z 10064 TID-1w7iwu Sidekiq::Extensions::DelayedMailer JID-bcae8ea4974ecfe280e411bd INFO: done: 0.858 sec
2013-11-13T13:23:51Z 10064 TID-1n41gu UploadWorker JID-03fe3dee40f6390f5cec1d93 INFO: start
2013-11-13T13:23:54Z 10064 TID-1n41gu UploadWorker JID-03fe3dee40f6390f5cec1d93 INFO: done: 2.779 sec
2013-11-13T13:23:54Z 10064 TID-1w7iwu Sidekiq::Extensions::DelayedMailer JID-44f75877c5919302c9ded4fe INFO: start
2013-11-13T13:23:54Z 10064 TID-1w7iwu Sidekiq::Extensions::DelayedMailer JID-44f75877c5919302c9ded4fe INFO: done: 0.038 sec
The issue is, only the mails from sidekiq are shown as sent in log but arent delivered. Other mails from devise n custom mail do get delivered.
Are you sure your development email settings are set correctly? Try setting the following in config/development.rb:
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
config.action_mailer.smtp_settings = {
:address => '127.0.0.1',
:port => '587',
}
I am trying to send mail using sendmail settings but i am not receiving the mail I can see the mail sent in development log.
config/application.rb
config.action_mailer.delivery_method = :sendmail
config.action_mailer.sendmail_settings = {
:location => '/usr/sbin/sendmail',
:arguments => '-i -t'
}
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
mailers/Notifier.rb
class Notifier < ActionMailer::Base
default :from => "deepika#xxx.com"
def welcome_email
mail(:to => "deepika#xxx.com", :subject => "Welcome to My Site test mail")
end
end
And i am calling Notifier.welcome_email.deliver from index method.
I can see log
Sent mail to deepika#xxx.com (339ms)
Date: Wed, 10 Apr 2013 15:16:33 +0530
From: deepika#xxx.com
To: deepika#xxx.com
Message-ID: <516534f983356_30f3262c7c84610d2#cybage-virtual-machine.mail>
Subject: Welcome to My Site test mail
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
<p>Thanks for joining and have a great day!</p>
But i am not receiving mail.
when i do service sendmail status i am getting
MSP: is run via cron (20m)
MTA: 123995 /usr/sbin/sendmail-mta -Am -L sm-mta -bd -q10m
UID PID PPID C STIME TTY TIME CMD
root 123995 1 0 15:36 ? 00:00:00 sendmail: MTA: accepting connections
Daemon Status: (process 132996) Queue runner
Current number of children: 1
QueueDir free disk space (in blocks): 285222800
Load average: 1
Child Process 139595 Status: accepting connections
Child Process 144035 Status: console socket child
QUE: Same as MTA
Also when i do vi /var/mail/root, I am getting following
This is a MIME-encapsulated message
--r3A9kDux012954.1365587178/cybage-virtual-machine.cybage.com
The original message was received at Wed, 10 Apr 2013 15:02:21 +0530
from localhost
with id r3Adsdsd9WLU5012559
----- The following addresses had permanent fatal errors -----
<deepika#xxx.com>
(reason: Client was not authenticated)
----- Transcript of session follows -----
... while talking to mail.xxx.com.:
>>> MAIL From:<> SIZE=268814
<<< 530 5.7.1 Client was not authenticated
Service unavailable
Can you please tell me what is the reason behind not receiving mail.
If I click destroy on any record for my 3 models models, the user gets logged out. I'm using Devise and Ominauth.
#This logs out a user
def destroy
#rating = Rating.find(params[:id])
#rating.destroy
end
Started POST "/ratings/29" for 192.168.1.103 at 2011-02-26 20:11:45 +0000
Processing by RatingsController#destroy as HTML
Parameters: {"id"=>"29"}
User Load (0.5ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 2 LIMIT 1
Rating Load (0.3ms) SELECT `ratings`.* FROM `ratings` WHERE `ratings`.`id` = 29 LIMIT 1
SQL (0.0ms) BEGIN
AREL (0.5ms) DELETE FROM `ratings` WHERE `ratings`.`id` = 29
SQL (2.7ms) COMMIT
Request
Parameters:
None
Show session dump
session_id: "16a92c418fdfa8966b60b09e76346443"
Show env dump
GATEWAY_INTERFACE: "CGI/1.1"
HTTP_ACCEPT: "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"
HTTP_ACCEPT_CHARSET: "ISO-8859-1,utf-8;q=0.7,*;q=0.3"
HTTP_ACCEPT_ENCODING: "gzip,deflate,sdch"
HTTP_ACCEPT_LANGUAGE: "en-US,en;q=0.8"
HTTP_CACHE_CONTROL: "max-age=0"
HTTP_CONNECTION: "keep-alive"
HTTP_COOKIE: "_traitly_session=BAh7BkkiD3Nlc3Npb25faWQGOgZFRiIlMTk5NDExYjNjMWMzY2U1NWIwZDNjYjg2Y2FiMGNiNzY%3D--4c140502f8a075f61742fdf11e6fc7100722ca14"
HTTP_HOST: "192.168.1.105:3000"
HTTP_IF_NONE_MATCH: "\"2d7f4ba60c47e0cf39f1361e2274fa89\""
HTTP_REFERER: "http://192.168.1.105:3000/subjects"
HTTP_USER_AGENT: "Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.82 Safari/534.16"
HTTP_VERSION: "HTTP/1.1"
PATH_INFO: "/subjects"
QUERY_STRING: ""
REMOTE_ADDR: "192.168.1.103"
REMOTE_HOST: "192.168.1.103"
REQUEST_METHOD: "GET"
REQUEST_PATH: "/"
REQUEST_URI: "http://192.168.1.105:3000/subjects"
SCRIPT_NAME: ""
SERVER_NAME: "192.168.1.105"
SERVER_PORT: "3000"
SERVER_PROTOCOL: "HTTP/1.1"
SERVER_SOFTWARE: "WEBrick/1.3.1 (Ruby/1.9.2/2010-12-25)"
action_controller.instance: #<SubjectsController:0x90ecc1c #action_has_layout=true, #view_context_class=nil, #_headers={"Content-Type"=>"text/html"}, #_status=200, #_response=#<ActionDispatch::Response:0x90ecb68 ......Too long - had to cut it off
action_dispatch.cookies: {"_traitly_session"=>"BAh7BkkiD3Nlc3Npb25faWQGOgZFRiIlMTk5NDExYjNjMWMzY2U1NWIwZDNjYjg2Y2FiMGNiNzY=--4c140502f8a075f61742fdf11e6fc7100722ca14"}
action_dispatch.parameter_filter: [:password, :password, :password_confirmation]
action_dispatch.remote_ip: 192.168.1.103
action_dispatch.request.content_type: nil
action_dispatch.request.formats: [text/html]
action_dispatch.request.parameters: {"action"=>"index", "controller"=>"subjects"}
action_dispatch.request.path_parameters: {:action=>"index", :controller=>"subjects"}
action_dispatch.request.query_parameters: {}
action_dispatch.request.request_parameters: {}
action_dispatch.request.unsigned_session_cookie: {"session_id"=>"199411b3c1c3ce55b0d3cb86cab0cb76"}
action_dispatch.secret_token: "b3dc65e5cc9d1af31fb06160a604132f5a1f4d13edc313d74cb1bfd7e63994d429f6e8032669ea26ff4a8dab66b79f6070f8449b4a422a7862bb4307a4d84416"
rack.errors: #<IO:<STDERR>>
rack.input: #<StringIO:0x913578c>
rack.multiprocess: false
rack.multithread: false
rack.request.cookie_hash: {"_traitly_session"=>"BAh7BkkiD3Nlc3Npb25faWQGOgZFRiIlMTk5NDExYjNjMWMzY2U1NWIwZDNjYjg2Y2FiMGNiNzY=--4c140502f8a075f61742fdf11e6fc7100722ca14"}
rack.request.cookie_string: "_traitly_session=BAh7BkkiD3Nlc3Npb25faWQGOgZFRiIlMTk5NDExYjNjMWMzY2U1NWIwZDNjYjg2Y2FiMGNiNzY%3D--4c140502f8a075f61742fdf11e6fc7100722ca14"
rack.request.query_hash: {}
rack.request.query_string: ""
rack.run_once: false
rack.session: {"session_id"=>"199411b3c1c3ce55b0d3cb86cab0cb76"}
rack.session.options: {:path=>"/", :domain=>nil, :expire_after=>nil, :secure=>false, :httponly=>true, :id=>"199411b3c1c3ce55b0d3cb86cab0cb76"}
rack.url_scheme: "http"
rack.version: [1, 1]
warden: #<Warden::Proxy:0x9133bf8 #winning_strategies={}, #users={:user=>nil}, #env={"GATEWAY_INTERFACE"=>"CGI/1.1", "PATH_INFO"=>"/subjects", "QUERY_STRING"=>"", "REMOTE_ADDR"=>"192.168.1.103", "REMOTE_HOST"=>"192.168.1.103", "REQUEST_METHOD"=>"GET", "REQUEST_URI"=>"http://192.168.1.105:3000/subjects", "SCRIPT_NAME"=>"", "SERVER_NAME"=>"192.168.1.105", "SERVER_PORT"=>"3000", "SERVER_PROTOCOL"=>"HTTP/1.1", "SERVER_SOFTWARE"=>"WEBrick/1.3.1 (Ruby/1.9.2/2010-12-25)", "HTTP_HOST"=>"192.168.1.105:3000", "HTTP_CONNECTION"=>"keep-alive", "HTTP_REFERER"=>"http://192.168.1.105:3000/subjects", "HTTP_CACHE_CONTROL"=>"max-age=0", "HTTP_USER_AGENT"=>"Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.82 Safari/534.16", "HTTP_ACCEPT"=>"application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5", "HTTP_ACCEPT_ENCODING"=>"gzip,deflate,sdch", "HTTP_ACCEPT_LANGUAGE"=>"en-US,en;q=0.8", "HTTP_ACCEPT_CHARSET"=>"ISO-8859-1,utf-8;q=0.7,*;q=0.3", "HTTP_COOKIE"=>"_traitly_session=BAh7BkkiD3Nlc3Npb25faWQGOgZFRiIlMTk5NDExYjNjMWMzY2U1NWIwZDNjYjg2Y2FiMGNiNzY%3D--4c140502f8a075f61742fdf11e6fc7100722ca14", "HTTP_IF_NONE_MATCH"=>"\"2d7f4ba60c47e0cf39f1361e2274fa89\"", "rack.version"=>[1, 1], "rack.input"=>#<StringIO:0x913578c>, "rack.errors"=>#<IO:<STDERR>>, "rack.multithread"=>false, "rack.multiprocess"=>false, "rack.run_once"=>false, "rack.url_scheme"=>"http", "HTTP_VERSION"=>"HTTP/1.1", "REQUEST_PATH"=>"/", "action_dispatch.parameter_filter"=>[:password, :password, :password_confirmation], "action_dispatch.secret_token"=>"b3dc65e5cc9d1af31fb06160a604132f5a1f4d13edc313d74cb1bfd7e63994d429f6e8032669ea26ff4a8dab66b79f6070f8449b4a422a7862bb4307a4d84416", "action_dispatch.remote_ip"=>192.168.1.103, "rack.session"=>{"session_id"=>"199411b3c1c3ce55b0d3cb86cab0cb76"}, "rack.session.options"=>{:path=>"/", :domain=>nil, :expire_after=>nil, :secure=>false, :httponly=>true, :id=>"199411b3c1c3ce55b0d3cb86cab0cb76"}, "rack.request.cookie_string"=>"_traitly_session=BAh7BkkiD3Nlc3Npb25faWQGOgZFRiIlMTk5NDExYjNjMWMzY2U1NWIwZDNjYjg2Y2FiMGNiNzY%3D--4c140502f8a075f61742fdf11e6fc7100722ca14", "rack.request.cookie_hash"=>{"_traitly_session"=>"BAh7BkkiD3Nlc3Npb25faWQGOgZFRiIlMTk5NDExYjNjMWMzY2U1NWIwZDNjYjg2Y2FiMGNiNzY=--4c140502f8a075f61742fdf11e6fc7100722ca14"}, "action_dispatch.cookies"=>{"_traitly_session"=>"BAh7BkkiD3Nlc3Npb25faWQGOgZFRiIlMTk5NDExYjNjMWMzY2U1NWIwZDNjYjg2Y2FiMGNiNzY=--4c140502f8a075f61742fdf11e6fc7100722ca14"}, "action_dispatch.request.unsigned_session_cookie"=>{"session_id"=>"199411b3c1c3ce55b0d3cb86cab0cb76"}, "warden"=>#<Warden::Proxy:0x9133bf8 ...>, "action_dispatch.request.path_parameters"=>{:action=>"index", :controller=>"subjects"}, "action_controller.instance"=>#<SubjectsController:0x90ecc1c #action_has_layout=true, #view_context_class=nil, #_headers={"Content-Type"=>"text/html"}, #_status=200, #_response=#<ActionDispatch::Response:0x90ecb68 #writer=#<Proc:0x90ecaf0#/usr/local/rvm/gems/ruby-1.9.2-p136#traitly/gems/actionpack-3.0.4/lib/action_dispatch/http/response.rb:43 (lambda)>, #block=nil, #length=0, #header={}, #status=200, #body=[], #cookie=[], #sending_file=false, #blank=false, #cache_control={}, #etag=nil, #request=#<ActionDispatch::Request:0x90ecb7c #env={...}, #fullpath="/subjects", #request_method="GET", #filtered_parameters={"action"=>"index", "controller"=>"subjects"}, #method="GET">>, #_request=#<ActionDispatch::Request:0x90ecb7c #env={...}, #fullpath="/subjects", #request_method="GET", #filtered_parameters={"action"=>"index", "controller"=>"subjects"}, #method="GET">, #_env={...}, #lookup_context=#<ActionView::LookupContext:0x90ec4c4 #details_key=nil, #details={:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:html], :locale=>[:en, :en]}, #skip_default_locale=false, #frozen_formats=false, #view_paths=[/root/projects/traitly/app/views, /usr/local/rvm/gems/ruby-1.9.2-p136#traitly/gems/devise-1.1.7/app/views]>, #_action_name="index", #_response_body=nil, #_config={}, #current_user=nil>, "action_dispatch.request.content_type"=>nil, "action_dispatch.request.request_parameters"=>{}, "rack.request.query_string"=>"", "rack.request.query_hash"=>{}, "action_dispatch.request.query_parameters"=>{}, "action_dispatch.request.parameters"=>{"action"=>"index", "controller"=>"subjects"}, "action_dispatch.request.formats"=>[t
You're using Rails 3, which uses JavaScript to issue delete requests. Because the request isn't set up properly, your log is showing Started POST instead of the correct Started DELETE.
The request will also not include the required CSRF data, and as of Rails 3.0.4 the session is silently reset instead of throwing an ActionController::InvalidAuthenticityToken error. This is why you suspect the authentication issue lies with Devise, but it is actually being triggered within Rails itself.
To fix this include the following in your layout:
<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>
Also ensure you have an updated rails.js (which contains the JavaScript code used for delete requests). The Rails 3.0.4 upgrade notes explain the issue in more detail.
If you're using the jquery rails.js replacement, you can get the updated version from here.
This is the error I see:
Timeout::Error in Devise/registrationsController#create
execution expired
This is what my development.rb looks like:
MyApp::Application.configure do
# Settings specified here will take precedence over those in config/environment.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the webserver when you make code changes.
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_view.debug_rjs = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = true
# Print deprecation notices to the Rails logger
config.active_support.deprecation = :log
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
config.action_mailer.default_url_options = { :host => 'localhost:3000' } #Make sure to set 'host' to domain name in production.
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = false
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default :charset => "utf-8"
end
I check my logs, this is what I see, once I click the 'Submit' button on the Registration form:
Started GET "/users/register" for 127.0.0.1 at 2011-02-11 19:19:23 -0500
Processing by Devise::RegistrationsController#new as HTML
nil
Rendered devise/shared/_links.erb (2.4ms)
Rendered devise/registrations/new.html.erb within layouts/application (98.1ms)
Completed 200 OK in 160ms (Views: 109.0ms | ActiveRecord: 0.0ms)
Started POST "/users" for 127.0.0.1 at 2011-02-11 19:20:03 -0500
Processing by Devise::RegistrationsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"qWs4IOH3L+GT/Sld8rZRlhXi8JM0pe0NtWG4Tn9XRIU=", "user"=>{"username"=>"marcamillion", "f_name"=>"marc", "l_name"=>"gayle", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "email"=>"marc#amillion.com"}, "commit"=>"Register"}
nil
WARNING: Can't mass-assign protected attributes: f_name, l_name
User Load (0.2ms) SELECT "users"."id" FROM "users" WHERE (LOWER("users"."email") = LOWER('marc#amillion.com')) LIMIT 1
User Load (0.1ms) SELECT "users"."id" FROM "users" WHERE (LOWER("users"."username") = LOWER('marcamillion')) LIMIT 1
CACHE (0.0ms) SELECT "users"."id" FROM "users" WHERE (LOWER("users"."email") = LOWER('marc#amillion.com')) LIMIT 1
User Load (0.2ms) SELECT "users".* FROM "users" WHERE ("users"."confirmation_token" = 'DCo8QgqWQfnYWq20n5Uf') LIMIT 1
AREL (31.0ms) INSERT INTO "users" ("email", "encrypted_password", "password_salt", "reset_password_token", "remember_token", "remember_created_at", "sign_in_count", "current_sign_in_at", "last_sign_in_at", "current_sign_in_ip", "last_sign_in_ip", "username", "f_name", "l_name", "created_at", "updated_at", "invitation_token", "invitation_sent_at", "plan_id", "current_state", "confirmation_token", "confirmed_at", "confirmation_sent_at") VALUES ('marc#amillion.com', '$2a$10$55hQTGZpUKbeT5n30/eyau96jf5zzd18t19jV/Y4g8Urou/El4vKy', '$2a$10$55hQTGZpUKbeT5n30/eyau', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'marcamillion', NULL, NULL, '2011-02-12 00:20:03.699983', '2011-02-12 00:20:03.699983', NULL, NULL, NULL, NULL, 'DCo8QgqWQfnYWq20n5Uf', NULL, '2011-02-12 00:20:03.699855')
Rendered devise/mailer/confirmation_instructions.html.erb (1.0ms)
Sent mail to marc#amillion.com (30009ms)
Date: Fri, 11 Feb 2011 19:20:03 -0500
From: no-reply#myapp.com
To: marc#amillion.com
Message-ID: <4d55d233bfe9f_bd4880443b3c837ee#MyMacBook-Pro.local.mail>
Subject: Confirmation instructions
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
<p>Welcome marc#amillion.com!</p>
<p>You can confirm your account through the link below:</p>
<p>Confirm my account</p>
Completed in 30349ms
Timeout::Error (execution expired):
I am assuming you don't have an SMTP server running locally. Unless you really need the mail to be delivered in development, then you can remove this stuff and it should not error on you:
config.action_mailer.default_url_options = { :host => 'localhost:3000' } #Make sure to set 'host' to domain name in production.
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = false
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default :charset => "utf-8"
If you do want mail delivered in dev, then google setting up smtp server. Or you can even use something like gmail as an SMTP server