I am trying to enable my Rails application to receive email from a Gmail Account. I follow this screencast : Receiving Email with Mailman .
I tried to the the polling for emails from my Gmail account, so that everytime somebody send an email, my app will receive the message and then update the database with this message accordingly.
But when I tried to run 'script/mailman_serve' to start the server and the polling, I got an error like this one below:
olins-MacBook-Pro:rentlord Ryzal$ script/mailman_server
I, [2016-02-26T02:07:58.104774 #23700] INFO -- : Mailman v0.7.3 started
I, [2016-02-26T02:07:58.105083 #23700] INFO -- : Rails root found in ., requiring environment...
/Users/Ryzal/Desktop/Sites/rentlord/config/application.rb:59: warning: already initialized constant OpenSSL::SSL::VERIFY_PEER
I, [2016-02-26T02:08:07.225640 #23700] INFO -- : POP3 receiver enabled (@pop.gmail.com).
I, [2016-02-26T02:08:07.266177 #23700] INFO -- : Polling enabled. Checking every 60 seconds.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/pop.rb:1005:in `check_response_auth': -ERR USER _who_? k19mb6670915wjq (Net::POPAuthenticationError)
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/pop.rb:905:in `block in auth'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/pop.rb:1012:in `critical'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/pop.rb:904:in `auth'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/pop.rb:566:in `do_start'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/pop.rb:536:in `start'
from /Library/Ruby/Gems/2.0.0/gems/mailman-0.7.3/lib/mailman/receiver/pop3.rb:36:in `connect'
from /Library/Ruby/Gems/2.0.0/gems/mailman-0.7.3/lib/mailman/application.rb:139:in `block in polling_loop'
from /Library/Ruby/Gems/2.0.0/gems/mailman-0.7.3/lib/mailman/application.rb:137:in `loop'
from /Library/Ruby/Gems/2.0.0/gems/mailman-0.7.3/lib/mailman/application.rb:137:in `polling_loop'
from /Library/Ruby/Gems/2.0.0/gems/mailman-0.7.3/lib/mailman/application.rb:87:in `run'
from /Library/Ruby/Gems/2.0.0/gems/mailman-0.7.3/lib/mailman/application.rb:15:in `run'
from script/mailman_server:25:in `<main>'
And this is my mailman_server file:
#!/usr/bin/env ruby
require "rubygems"
require "bundler/setup"
require "mailman"
#Mailman.config.logger = Logger.new("log/mailman.log")
Mailman.config.pop3 = {
server: 'pop.gmail.com', port: 995, ssl: true,
username: ENV["[email protected]"],
password: ENV["xxxxxx"]
}
Mailman::Application.run do
default do
begin
Post.receive_mail(message)
rescue Exception => e
Mailman.logger.error "Exception occurred while receiving message:\n#{message}"
Mailman.logger.error [e, *e.backtrace].join("\n")
end
end
end
Could anybody help? Thanks!
########################### UPDATE ##########################
I also have enable POP setting on my gmail account, but still the same error occurs. This is my POP setting:
I was able to reproduce error only in one case. If I had username
blank.
If you could use this code for investigation. Put it wherever outside the project, make sure mailman gem is installed and run file twice. Once hardcode user name and second time leave it as nil
:
#!/usr/bin/env ruby
require "mailman"
username = ''
### OR ###
username = '[email protected]'
puts "Using username='#{username}'..."
Mailman.config.pop3 = {
server: 'pop.gmail.com', port: 995, ssl: true,
username: username,
password: 'password'
}
Mailman::Application.run do
default do
begin
puts message
rescue Exception => e
Mailman.logger.error "Exception occurred while receiving message:\n#{message}"
Mailman.logger.error [e, *e.backtrace].join("\n")
end
end
end
Using username=''...
I, [2016-03-02T00:01:44.059312 #16088] INFO -- : Mailman v0.7.3 started
I, [2016-03-02T00:01:44.059400 #16088] INFO -- : POP3 receiver enabled (@pop.gmail.com).
I, [2016-03-02T00:01:44.070004 #16088] INFO -- : Polling enabled. Checking every 60 seconds.
/usr/local/Cellar/ruby/2.2.2/lib/ruby/2.2.0/net/pop.rb:1005:in
`check_response_auth': -ERR USER _who_? z184mb105814233wlc (Net::POPAuthenticationError)
Using username='[email protected]'...
I, [2016-03-02T00:05:35.715465 #16178] INFO -- : Mailman v0.7.3 started
I, [2016-03-02T00:05:35.715540 #16178] INFO -- : POP3 receiver enabled ([email protected]@pop.gmail.com).
I, [2016-03-02T00:05:35.726853 #16178] INFO -- : Polling enabled. Checking every 60 seconds.
I, [2016-03-02T00:06:38.281546 #16178] INFO -- : Got new message from '[email protected]' with subject 'http://stackoverflow.com/questions/35642212/popauthenticationerror-mailman-error-when-polling-from-gmail-account'.
Return-Path: <[email protected]>
Received: by 10.79.115.146 with SMTP id y28csa1793673ivf; Tue, 01 Mar 2016 15:06:05 -0800
Received: from mail-lf0-x22f.google.com (mail-lf0-x22f.google.com. [2a00:1450:4010:c07::22f]) by mx.google.com with ESMTPS id jm5dsi1257241lbc.1.2016.03.01.15.06.05 for
(...)
X-Mailer: Apple Mail (2.3124)
http://stackoverflow.com/questions/35642212/popauthenticationerror-mailma=
n-error-when-polling-from-gmail-account=