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

Non meaningful error when password is incorrect #96

Open
stevedomin opened this issue Mar 9, 2016 · 19 comments
Open

Non meaningful error when password is incorrect #96

stevedomin opened this issue Mar 9, 2016 · 19 comments

Comments

@stevedomin
Copy link

While attempting to send through my Sendgrid account I got stuck on this error for ages. Basically my password had some special characters and I guess I needed to do some escaping, unfortunately the error reported wasn't helpful at all.

I'm wondering if these anything we can do to show a more meaningful error to the user. I'm more than happy to contribute, but I'll need some guidance.

I had to uncomment some logging to figure out the issue (see logs below).

(This is elixir, not erlang, sorry about that)

iex(1)> :gen_smtp_client.send_blocking({"from", ["to"], "Subject: testing\r\nFrom: Andrew Thompson \r\nTo: Some Dude \r\n\r\nThis is the email body"}, [relay: "smtp.sendgrid.net", username: "username", password: "passwordwithspecialcharacter", auth: :always, tls: :always])
connected to smtp.sendgrid.net; banner was  SG ESMTP service ready at x.sendgrid.net

Extensions are [{<<"8BITMIME">>,true},
                {<<"PIPELINING">>,true},
                {<<"SIZE">>,<<"31457280">>},
                {<<"STARTTLS">>,true},
                {<<"AUTH">>,<<"PLAIN LOGIN">>},
                {<<"AUTH=PLAIN">>,<<"LOGIN">>}]
Extensions are [{<<"8BITMIME">>,true},
                {<<"PIPELINING">>,true},
                {<<"SIZE">>,<<"31457280">>},
                {<<"STARTTLS">>,true},
                {<<"AUTH">>,<<"PLAIN LOGIN">>},
                {<<"AUTH=PLAIN">>,<<"LOGIN">>}]
username prompt
password prompt
password rejected: 535 Authentication failed: Bad username / password
** (ArgumentError) argument error
               :erlang.++("username", [0 | "passwordwithspecialcharacter"])
    (gen_smtp) src/gen_smtp_client.erl:400: :gen_smtp_client.do_AUTH_each/4
    (gen_smtp) src/gen_smtp_client.erl:322: :gen_smtp_client.try_AUTH/3
    (gen_smtp) src/gen_smtp_client.erl:203: :gen_smtp_client.do_smtp_session/3
    (gen_smtp) src/gen_smtp_client.erl:142: :gen_smtp_client.try_smtp_sessions/4
@Vagabond
Copy link
Collaborator

Vagabond commented Mar 9, 2016

Can you say what the special character is?

You could try something like this:

AuthString = base64:encode(io_lib:format("\0~s\0~s", [Username, Password])),

@Vagabond
Copy link
Collaborator

Vagabond commented Mar 9, 2016

@stevedomin
Copy link
Author

I'm getting the following error:

** (ArithmeticError) bad argument in arithmetic expression
      (stdlib) base64.erl:81: :base64.encode_l/1
      (stdlib) base64.erl:67: :base64.encode/1
    (gen_smtp) src/gen_smtp_client.erl:400: :gen_smtp_client.do_AUTH_each/4
    (gen_smtp) src/gen_smtp_client.erl:322: :gen_smtp_client.try_AUTH/3
    (gen_smtp) src/gen_smtp_client.erl:203: :gen_smtp_client.do_smtp_session/3
    (gen_smtp) src/gen_smtp_client.erl:142: :gen_smtp_client.try_smtp_sessions/4

The password was generated by 1Password so it contains /, % and )

@Vagabond
Copy link
Collaborator

Vagabond commented Mar 9, 2016

Sorry, I should have tested it. Try this:

AuthString = base64:encode(list_to_binary(io_lib:format("\0~s\0~s", [Username, Password]))),

@stevedomin
Copy link
Author

It's now rejecting the password twice and then I get an error tuple:

password rejected: 535 Authentication failed: Bad username / password
password rejected: 535 Authentication failed: Bad username / password
{:error, :retries_exceeded,
 {:network_failure, "smtp.sendgrid.net", {:error, :closed}}}

@Vagabond
Copy link
Collaborator

Is it possible to give me a credential on your account for testing?

@stevedomin
Copy link
Author

You can create a free account at https://sendgrid.com/, comes with 12k emails free.

That's probably the simplest, otherwise happy to figure out a way to give you credentials (pgp?)

@Vagabond
Copy link
Collaborator

I will give it a try.

@Vagabond
Copy link
Collaborator

Ugh, they want to validate my 'company' and a bunch of other nonsense, which I don't really have.

@stevedomin
Copy link
Author

Ah crap, do you have a pgp key (or a keybase.io account)?

@Vagabond
Copy link
Collaborator

-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v2

mQENBFSz/scBCADF0IVZU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/ZyvXsbNA4v55NY34
PQm/XNZ0Bx4iPz0bOadWxvGovVl2rCIWuXoWVIDCKEkHOYjnDaJuT+eZ6Ni3UTwA
OeHU3Qx8HmkmcviNiLH5piUpDLzdxiCO63cAEQEAAYkBHwQYAQgACQUCVLP+xwIb
DAAKCRDkx9MV3yU5cAL/B/0Z59xsclJdYt3+09cuZ0y0qRaxPcGQRrRRvu3jhB8V
kq3CqfpJ2Kb5V1qHc/V8d20Bx4xLidx1S5XTYErRFbKeYzCUThLpTNEZvmbbvtyP
pnLiGcnaaii+pZ+f8lxL7Mz3T8pJCjsY/cmi0PDwEwwtOaNFrXJSJPZJ6MzuFzte
HkWkdlHlsweOfZiZlh7Li8V+oUwVCkYM57ZB1bb4pzDmhDcBiaMYofK4FweHdhyy
GGsTdxJFJmsWrEDEp9ckOcR0NR61TNhPwb9JncJZwCtr+isR6F71sN1vg7VP7LyQ
Evu8JiiLkeHc0NZnIZO+9nXHJEURjkcTxAu/NDjuZoFT
=budR
-----END PGP PUBLIC KEY BLOCK-----

@stevedomin
Copy link
Author

account.zip

@Vagabond
Copy link
Collaborator

Ok, so I got the credentials, but I can't authenticate to their SMTP server with the credentials using their example here:

https://support.sendgrid.com/hc/en-us/articles/200182038-Testing-your-connectivity-to-Sendgrid-s-SMTP-relay-using-Telnet

I get the same Bad username / password error

@Vagabond
Copy link
Collaborator

Ok, my sendgrid account got activated (I have no idea why).

If I use the username for the account. not the email address, I can authenticate and send via sendgrid.

@stevedomin
Copy link
Author

Ok, this was indeed the issue in my case (I created some testing credentials with a password without special characters, so I thought this was the issue).

Do you think we could make the error message that gen_stmp gives better? In the current form you need to manually uncomment logging statement directly in the code to figure out what's happening.

@Vagabond
Copy link
Collaborator

Yeah, that is a legitimate concern.

I tried to reproduce your original error with the 'argument' error, but I could not, we should fix that too.

@keichan34
Copy link
Contributor

** (ArgumentError) argument error
               :erlang.++("username", [0 | "passwordwithspecialcharacter"])

I was able to reproduce this using a binary (default for Elixir) instead of a char list for Username and Password arguments.

@mworrell
Copy link
Collaborator

@keichan34 looking at the current code I suspect your issue has been resolved.

@stevedomin Is this still a problem?

@mworrell
Copy link
Collaborator

In general: we could add a flag to enable the logging of all client/server communication for a specific request.

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

4 participants