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

IMAP error with Kumar scrpit #92

Open
c-hering opened this issue Dec 2, 2015 · 11 comments
Open

IMAP error with Kumar scrpit #92

c-hering opened this issue Dec 2, 2015 · 11 comments

Comments

@c-hering
Copy link

c-hering commented Dec 2, 2015

When I startup the script with all of the correct info in the right places, I get an IMAP error and I have no idea what from.

@kashyapakshay
Copy link
Contributor

Might be because Gmail complains of 'less secure apps' if OAuth2 isn't used for authentication. Try turning 'less secure apps' on for the account: https://www.google.com/settings/security/lesssecureapps

@c-hering
Copy link
Author

c-hering commented Dec 2, 2015

Ok, I'll try that out

@c-hering
Copy link
Author

c-hering commented Dec 2, 2015

It didn't work, I keep getting this; `get_tagged_response': Invalid arguments supplied to LOGIN. k3mb38185354qke (Net::IMAP::BadResponseError)

@kashyapakshay
Copy link
Contributor

This is the node script? I'll look at it.

@c-hering
Copy link
Author

c-hering commented Dec 2, 2015

#!/usr/bin/env ruby

require 'dotenv'
require 'gmail'

Dotenv.load

GMAIL_USERNAME = ENV['xxxxxx@gmail.com']
GMAIL_PASSWORD = ENV['xxxxxxxx']

GMAIL = Gmail.connect(GMAIL_USERNAME,GMAIL_PASSWORD)
SCAM_EMAIL = 'xxxxxxx@gmail.com'

DB_NAME_REGEX = /\S+_staging/
KEYWORDS_REGEX = /sorry|help|wrong/i|test

def create_reply(subject)
GMAIL.compose do
to SCAM_EMAIL
subject "RE: #{subject}"
body "No problem. I've fixed it. \n\n Please be careful next time."
end
end

GMAIL.inbox.find(:unread, from: SCAM_EMAIL).each do |email|
if email.body.raw_source[KEYWORDS_REGEX] && (db_name = email.body.raw_source[DB_NAME_REGEX])
# Mark as read, add label and reply
email.read!
email.label('Database fixes')
reply = create_reply(email.subject)
GMAIL.deliver(reply)
end
end

@kashyapakshay
Copy link
Contributor

Ah, I see the issue. GMAIL_USERNAME and GMAIL_PASSWORD are set to the corresponding environment variables. So change those lines to:

GMAIL_USERNAME = 'xxxxxx@gmail.com'
GMAIL_PASSWORD = 'xxx'

and not

GMAIL_USERNAME = ENV['xxxxxx@gmail.com']

The latter causes it to look for an env variable called "xxxxxx@gmail.com"

@c-hering
Copy link
Author

c-hering commented Dec 2, 2015

Ok, So that fixed the first error, and a couple syntax errors popped up but I fixed those, now it is giving me the same as before but indicating to line 25; GMAIL.inbox.find(:unread, from: SCAM_EMAIL).each do |email|

@kashyapakshay
Copy link
Contributor

I see. I'm not sure why, maybe some one else can help with that. But I'd suggest you check if there are no unread emails from SCAM_EMAIL. 0 unread emails may throw an error.

@c-hering
Copy link
Author

c-hering commented Dec 2, 2015

Alright, will do. Thanks for all your help so far!

@kashyapakshay
Copy link
Contributor

No problem

@c-hering
Copy link
Author

c-hering commented Dec 3, 2015

Do you think that there could be any problems with the From command? I was looking at commands in IMAP that can cause problems easily and came across the From command.

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