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

SendEmail error: HTTP/1.1 505 HTTP Version not supported error #2

Closed
edwinyzh opened this issue Oct 29, 2020 · 29 comments
Closed

SendEmail error: HTTP/1.1 505 HTTP Version not supported error #2

edwinyzh opened this issue Oct 29, 2020 · 29 comments
Assignees
Labels
bug Something isn't working

Comments

@edwinyzh
Copy link

When calling the Indy-powered SendEmail I'm getting the HTTP/1.1 505 HTTP Version not supported error.

then I added the following line to TksAwsBaseService.GetUrl:
Result := UrlEncode(Result);
And now I'm getting the following new error:
HTTP/1.1 403 Forbidden.

Any idea? Thanks!

@edwinyzh
Copy link
Author

@gmurt,

It's strange, I'm using the same IAM user, it was ok when I tried several days ago with the 'VerifiedSenders' sample project. But now I tried again with the same set of access key and secret, I'm getting the HTTP/1.1 403 Forbidden error as well...

In this thread it seems that AWS returns details about the error. With ksAws is there a way to check detailed error like that?

Thanks!

@edwinyzh
Copy link
Author

Update 1: I confirm with the AWS CLI, the aws ses list-identities command successfully returned the verified email addresses. In other words, my IAM user access id and key are correct.

@gmurt
Copy link
Owner

gmurt commented Oct 29, 2020

Just pushed an update, it looks like it may have been to do with query/header encoding. Let me know if it's fixed, appears to be working for me now.

@gmurt gmurt self-assigned this Oct 29, 2020
@gmurt gmurt added the bug Something isn't working label Oct 29, 2020
@edwinyzh
Copy link
Author

Thanks @gmurt

To get the latest commit compiled, I had to change in ksAwsHash.pas the following line
C_UNSAFE_CHARS: array of Char = [' ',':', '/', '?', '#', '[', ']', '@', '!', '$', '&', '''', '(', ')', '*', '+', ',', ';', '='];
to
C_UNSAFE_CHARS: array[0..18] of Char = (' ',':', '/', '?', '#', '[', ']', '@', '!', '$', '&', '''', '(', ')', '*', '+', ',', ';', '=');

And unfortunately, I'm still getting the HTTP/1.1 403 Forbidden. error with both SendEmail and GetSenders.

I attached the testing code below:
TestKsAwsSesEmailSending_tmp.zip

@gmurt
Copy link
Owner

gmurt commented Oct 29, 2020

Both demo functions are working fine for me in XE4. 403 does indicate a credential issue, maybe declare your credentials as constants to ensure they do not have any spaces at the beginning or end.

image

@edwinyzh
Copy link
Author

Thanks @gmurt ! Good to know it works, I'll try again.
Another think I want to confirm - were you using Indy as the HTTP client to test?

@edwinyzh
Copy link
Author

Hey Graham,

With the same testing project I attached without further changes, after restarted my computer, now both the btnGeVerifiedSenders and btnSend are working!!!

Not sure why, maybe the constant switching of "direct connection vs shadowsocks (proxy) connection" on the computer caused the issue...

@gmurt
Copy link
Owner

gmurt commented Oct 30, 2020

Good to hear. Any further problems let me know.

@gmurt gmurt closed this as completed Oct 30, 2020
@edwinyzh
Copy link
Author

@gmurt,

I'm getting the HTTP/1.1 505 HTTP Version not supported error again, maybe due to my long email body text - over 1600 characters (260 words)? Because I guess the email message gets sent through URL? That'll exceed the length limit I think.

I think this kind of email body length is very normal.

@edwinyzh
Copy link
Author

edwinyzh commented Oct 30, 2020

Hi Graham,
After further testing, I found that the content of the email subject and body affects if the error will happen - email can be sent with simple subject and email body like the code I attached, but I'll get 403 or 505 error depending on the content of subject and/or body.

For example, the following code will work:

    msg := CreateSesMessage('edwin@a.com', 'john@b.com',
      'testing AWS SES email sending - '  + DateTimeToStr(Now),
      'the email was sent at: ' + DateTimeToStr(Now));

The following code does NOT work (notice the double quotes in the subject), it will produce the EIdHTTPProtocolException: HTTP/1.1 403 Forbidden error:

    msg := CreateSesMessage('edwin@a.com', 'john@b.com',
      'testing "AWS SES" email sending - '  + DateTimeToStr(Now),
      'the email was sent at: ' + DateTimeToStr(Now));

@gmurt
Copy link
Owner

gmurt commented Oct 30, 2020

Ok, I'll take a look. Can you also provide me a simple example which produces the 505 error on your machine?

This will help me identify the issue.

@gmurt gmurt reopened this Oct 30, 2020
@gmurt
Copy link
Owner

gmurt commented Oct 30, 2020

I believe the latest update will fix the 403 error when using Indy. If you can provide an example which produces the 505 that would help me fix that one.

@edwinyzh
Copy link
Author

I confirm with the latest update I'm no longer getting the 403 error, but only the EIdHTTPProtocolException: HTTP/1.1 505 HTTP Version not supported error. I will provide an example.

@edwinyzh
Copy link
Author

edwinyzh commented Oct 31, 2020

@gmurt , the following code will produce the 505 error. The code example was extracted from the sample I attached earlier - I just added double quotes to the email subject.

BTW, WWIW, I'm using a latest revision of Indy from the official repository: https://github.com/IndySockets/Indy

procedure TfrmMain.btnSendClick(Sender: TObject);
var
  msg: IksAwsSesMessage;
  ses: IksAwsSES;
begin
  ses := CreateSes(edtAccessKeyId.Text, edtAccessSecret.Text, awsUsEast1);

  // ok:
  //  msg := CreateSesMessage('edwin.yip@mydomain.com', 'anotheruser@mydomain.com',
  //    'testing AWS SES email sending - '  + DateTimeToStr(Now),
  //    'the email was sent at: ' + DateTimeToStr(Now));

  // will produce the  "EIdHTTPProtocolException: HTTP/1.1 505 HTTP Version not supported" error:
  msg := CreateSesMessage('edwin.yip@mydomain.com', 'anotheruser@mydomain.com',
    'testing "AWS SES" email sending - '  + DateTimeToStr(Now),
    'the email was sent at: ' + DateTimeToStr(Now));

  ses.SendEmail(msg);
end;

@gmurt
Copy link
Owner

gmurt commented Oct 31, 2020

Think it was the encoding of the space " " character. Please pull latest changes and retry.

@edwinyzh
Copy link
Author

Think it was the encoding of the space " " character. Please pull latest changes and retry.

Thanks Graham! I'll check it now. BTW, does SendEmail support html message? Thanks!

@gmurt
Copy link
Owner

gmurt commented Oct 31, 2020

Not sure, I've only tested with plain text messages. I'll close this issue, if there's a problem with html please open a new ticket and I'll take a look.

@gmurt gmurt closed this as completed Oct 31, 2020
@gmurt gmurt reopened this Oct 31, 2020
@gmurt
Copy link
Owner

gmurt commented Oct 31, 2020

Sorry I mis-read your last message. Thought you confirmed it was fixed. Please test and if the 505 is fixed I'll close this issue.

@edwinyzh
Copy link
Author

@gmurt,

The issue with double quotes in the subject has been fixed, but with body text like the following still emit the EIdHTTPProtocolException: HTTP/1.1 505 HTTP Version not supported error:

  cTestBody =
    'Dear E,' + sLineBreak +
    '' + sLineBreak +
    'This the “re-bbb b”.' + sLineBreak +
    'I''m - didn''t doesn’t alter.' + sLineBreak +
    '' + sLineBreak +
    'policy:' + sLineBreak +
    '-	Wrs.' + sLineBreak +
    '-	Wres.' + sLineBreak +
    '-	Dt 2 mo(plo).' + sLineBreak +
    '-	If you on: UUUIAUSFD (val, 30 cent dy-di ‘test’. on). ' + sLineBreak +
    '' + sLineBreak +
    'Here:' + sLineBreak +
    '-	download from https://google.com' + sLineBreak +
    '-	key: john-jdo#001-01201030-c826-e061-9208-50ad-7c56-6629-023c-bb5c' + sLineBreak +
    '' + sLineBreak +
    'I .. didn’t hap questions.' + sLineBreak +
    '' + sLineBreak +
    'Edwin Doe – the of aa/bb' + sLineBreak +
    'Best Regards.';
var
  msg: IksAwsSesMessage;
begin
    msg := CreateSesMessage(cToEmail, cSendFrom, cSubject, cTestBody);
    ses.SendEmail(msg);
end;

@gmurt
Copy link
Owner

gmurt commented Oct 31, 2020

Please can you supply me the full source for the unit so I can see how the constants are declared.

@edwinyzh
Copy link
Author

Attached.
TestKsAwsSesEmailSending002.zip

@gmurt
Copy link
Owner

gmurt commented Oct 31, 2020

Ok, hopefully now sorted! Let me know if it's fixed with the latest change.

@edwinyzh
Copy link
Author

Thanks again for the help @gmurt.
Unfortunately, with the same example without any code changes nor other changes on AWS, but just a rebuild, Now I get:
HTTP/1.1 403 Forbidden.

@gmurt
Copy link
Owner

gmurt commented Oct 31, 2020

Working fine here. Forbidden suggests it may be an issue with your credentials. Ensure that you are entering them without spaces etc. Just tested again with XE4/Indy. I'll try and make some improvements so more detailed error messages are displayed.

@gmurt
Copy link
Owner

gmurt commented Oct 31, 2020

Just googled, a 403 suggests that there may be a leading/trailing space added by mistake to your secret key. I tested and if I add a space to the Secret key I do get the 403 error. I'll make sure the keys are "trimmed" with the next update but please check this.

@edwinyzh
Copy link
Author

Hello Graham,

I confirm there are no leading/trailing spaces added to the keys. It's the same test program we've been using in the past days. the 'subject' and 'body' were the only things that were changed during the test.

@gmurt
Copy link
Owner

gmurt commented Oct 31, 2020

I've just resynced the repo to my machine and run your example in XE4 with the standard Indy which ships with that version.

The only change I've made is to hard code the credentials and changed the email addresses. It works fine, it "has" to be a credential issue at your end, there's nothing else it can be. Maybe create some new credentials in IAM and test in case your existing credentials have been invalidated.

image

image

@edwinyzh
Copy link
Author

edwinyzh commented Nov 1, 2020

@gmurt ,

Thanks for your help and sorry for all the troubles - not sure why, but today I re-run the programs (both, one real project, another is the test program I sent to you), without any changes, I tried several times, and the email sending worked!

I'm also puzzled. The only thing that's changed is the computer has been rebooted. But last night (my time) I did try to reboot the PC and try again, but the problem existed.

@gmurt
Copy link
Owner

gmurt commented Nov 1, 2020

Very strange but glad it's working now. I'll close this issue.

@gmurt gmurt closed this as completed Nov 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants