• Attempt to send email using AWS results in Socket closed by peer

    From Juan Rayas@21:1/5 to All on Wed Sep 1 11:58:47 2021
    Hi,

    I am teaching myself Ada and tried to create a simple program that sends an email if today's date equals my birthday :).

    I am using Gnat Studio 2021, Community edition, Ubuntu 20.0.4. I downloaded, built and installed AWS. I am sending the email as follows:

    procedure SendMail is
    Status : AWS.SMTP.Status;
    Auth : aliased constant SMTP.Authentication.Plain.Credential :=
    SMTP.Authentication.Plain.Initialize
    ("myAccount", "myPassword");
    Isp : SMTP.Receiver;

    begin
    New_Line;
    Isp :=
    SMTP.Client.Initialize
    ("smtp.gmail.com", Port => 465,
    Credential => Auth'Unchecked_Access);

    SMTP.Client.Send
    (Isp, From => SMTP.E_Mail ("Me", "myAccount"),
    To => SMTP.E_Mail ("Me", "myAccount"),
    Subject => "AWS test",
    Message => "This is a test",
    Status => Status);

    if not SMTP.Is_Ok (Status) then
    Text_IO.Put_Line
    ("Can't send message :" & SMTP.Status_Message (Status));
    end if;
    end SendMail;

    myAccount and myPassword are removed for the purposes of this post.

    When I run my program, the SendEmail procedure fails with the following message:

    raised AWS.SMTP.SERVER_ERROR : raised AWS.NET.SOCKET_ERROR : Receive : Socket closed by peer

    Does anyone know how to fix this when using the gmail server? Or perhaps I am using AWS incorrectly?

    Thanks,
    Juan

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dennis Lee Bieber@21:1/5 to All on Wed Sep 1 16:02:10 2021
    On Wed, 1 Sep 2021 11:58:47 -0700 (PDT), Juan Rayas
    <juan.m.rayas@gmail.com> declaimed the following:


    Does anyone know how to fix this when using the gmail server? Or perhaps I am using AWS incorrectly?

    My first suggestion would be: don't use the gmail server!

    If you must use it, you'll likely need to configure gmail for "less secure apps" (basically anything that isn't a Google product <G>).
    Google/Gmail wants OAUTH2 or something like that, along with TLS/SSL. "Less secure" means bypassing the OAUTH2 scheme.

    I wouldn't be surprised if they want you to set up a password for each device used to connect...



    --
    Wulfraed Dennis Lee Bieber AF6VN
    wlfraed@ix.netcom.com http://wlfraed.microdiversity.freeddns.org/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dmitry A. Kazakov@21:1/5 to Juan Rayas on Wed Sep 1 21:43:06 2021
    On 2021-09-01 20:58, Juan Rayas wrote:

    Does anyone know how to fix this when using the gmail server?

    No, but I guess that you must configure the SMTP client for TLS or else opportunistic TLS (StartTLS). Most mail servers do not accept
    unencrypted connections. I do not use AWS and its SMTP, maybe somebody
    who does might help you with it.

    --
    Regards,
    Dmitry A. Kazakov
    http://www.dmitry-kazakov.de

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Doctor Who@21:1/5 to juan.m.rayas@gmail.com on Thu Sep 2 06:03:11 2021
    On Wed, 1 Sep 2021 11:58:47 -0700 (PDT), Juan Rayas
    <juan.m.rayas@gmail.com> wrote:

    Hi,

    I am teaching myself Ada and tried to create a simple program that sends an email if today's date equals my birthday :).

    I am using Gnat Studio 2021, Community edition, Ubuntu 20.0.4. I downloaded, built and installed AWS. I am sending the email as follows:

    procedure SendMail is
    Status : AWS.SMTP.Status;
    Auth : aliased constant SMTP.Authentication.Plain.Credential :=
    SMTP.Authentication.Plain.Initialize
    ("myAccount", "myPassword");
    Isp : SMTP.Receiver;

    begin
    New_Line;
    Isp :=
    SMTP.Client.Initialize
    ("smtp.gmail.com", Port => 465,
    Credential => Auth'Unchecked_Access);

    SMTP.Client.Send
    (Isp, From => SMTP.E_Mail ("Me", "myAccount"),
    To => SMTP.E_Mail ("Me", "myAccount"),
    Subject => "AWS test",
    Message => "This is a test",
    Status => Status);

    if not SMTP.Is_Ok (Status) then
    Text_IO.Put_Line
    ("Can't send message :" & SMTP.Status_Message (Status));
    end if;
    end SendMail;

    myAccount and myPassword are removed for the purposes of this post.

    When I run my program, the SendEmail procedure fails with the following message:

    raised AWS.SMTP.SERVER_ERROR : raised AWS.NET.SOCKET_ERROR : Receive : Socket closed by peer

    Does anyone know how to fix this when using the gmail server? Or perhaps I am using AWS incorrectly?

    Thanks,
    Juan


    port 465 wants a TLS connection.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Iswara@21:1/5 to Juan Rayas on Thu Sep 2 10:29:32 2021
    On 02/09/2021 01.58, Juan Rayas wrote:
    Hi,

    I am teaching myself Ada and tried to create a simple program that sends an email if today's date equals my birthday :).

    I am using Gnat Studio 2021, Community edition, Ubuntu 20.0.4. I downloaded, built and installed AWS. I am sending the email as follows:

    procedure SendMail is
    Status : AWS.SMTP.Status;
    Auth : aliased constant SMTP.Authentication.Plain.Credential :=
    SMTP.Authentication.Plain.Initialize
    ("myAccount", "myPassword");
    Isp : SMTP.Receiver;

    begin
    New_Line;
    Isp :=
    SMTP.Client.Initialize
    ("smtp.gmail.com", Port => 465,
    Credential => Auth'Unchecked_Access);

    SMTP.Client.Send
    (Isp, From => SMTP.E_Mail ("Me", "myAccount"),
    To => SMTP.E_Mail ("Me", "myAccount"),
    Subject => "AWS test",
    Message => "This is a test",
    Status => Status);

    if not SMTP.Is_Ok (Status) then
    Text_IO.Put_Line
    ("Can't send message :" & SMTP.Status_Message (Status));
    end if;
    end SendMail;

    myAccount and myPassword are removed for the purposes of this post.

    When I run my program, the SendEmail procedure fails with the following message:

    raised AWS.SMTP.SERVER_ERROR : raised AWS.NET.SOCKET_ERROR : Receive : Socket closed by peer

    Does anyone know how to fix this when using the gmail server? Or perhaps I am using AWS incorrectly?

    Thanks,
    Juan


    Use a public email test server for testing program. Places like these: https://www.bing.com/search?form=MOZLBR&pc=MOZI&q=email+test+servers. It
    will show what's the received and sent responses.
    The Gmail server marked your message as spam or worse and simply ignored
    your message.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Randy Brukardt@21:1/5 to Dmitry A. Kazakov on Thu Sep 2 17:19:58 2021
    "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message news:sgol48$r20$1@gioia.aioe.org...
    ...
    Most mail servers do not accept unencrypted connections.

    That's news to me, as my mail server (you know, the one that runs
    Ada-Comment and the other ARG lists) doesn't support encrypted connections.
    I don't have any problem sending to GMail (I send copies of most of my
    personal mail there). Something else must be wrong.

    Randy.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Randy Brukardt@21:1/5 to Doctor Who on Thu Sep 2 17:22:53 2021
    "Doctor Who" <doc@tardis.org> wrote in message news:57j0jgd920r1al3ehsbilbs39041c3eeqd@4ax.com...
    ...
    port 465 wants a TLS connection.

    Good point. One uses port 25 for ordinary e-mail. One does not need to authenticate to most public e-mail servers (of course, if you don't, you'll
    be subjected to increased spam checks, but that usually isn't a problem if
    you aren't sending spam).

    Randy.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dmitry A. Kazakov@21:1/5 to Randy Brukardt on Fri Sep 3 09:32:27 2021
    On 2021-09-03 00:19, Randy Brukardt wrote:
    "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message news:sgol48$r20$1@gioia.aioe.org...
    ...
    Most mail servers do not accept unencrypted connections.

    That's news to me, as my mail server (you know, the one that runs
    Ada-Comment and the other ARG lists) doesn't support encrypted connections.
    I don't have any problem sending to GMail (I send copies of most of my personal mail there). Something else must be wrong.

    The question is with what settings. There are hundreds of combinations
    of Port x unencrypted|StartTLS|TLS x authentication method.

    The port 465 was intended for TLS, then it was depreciated. Then they introduced other ports. Legacy mail servers pissed that all on etc.

    From experience, getting a SMTP client working is real pain.

    --
    Regards,
    Dmitry A. Kazakov
    http://www.dmitry-kazakov.de

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Doctor Who@21:1/5 to mailbox@dmitry-kazakov.de on Fri Sep 3 10:59:31 2021
    On Fri, 3 Sep 2021 09:32:27 +0200, "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote:

    On 2021-09-03 00:19, Randy Brukardt wrote:
    "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
    news:sgol48$r20$1@gioia.aioe.org...
    ...
    Most mail servers do not accept unencrypted connections.

    That's news to me, as my mail server (you know, the one that runs
    Ada-Comment and the other ARG lists) doesn't support encrypted connections. >> I don't have any problem sending to GMail (I send copies of most of my
    personal mail there). Something else must be wrong.

    The question is with what settings. There are hundreds of combinations
    of Port x unencrypted|StartTLS|TLS x authentication method.

    The port 465 was intended for TLS, then it was depreciated. Then they >introduced other ports. Legacy mail servers pissed that all on etc.

    From experience, getting a SMTP client working is real pain.

    he is better off using his own provider's mail server on port 25, it
    will accept username/password as authentication.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Juan Rayas@21:1/5 to Doctor Who on Fri Sep 3 11:11:41 2021
    On Friday, September 3, 2021 at 1:59:33 AM UTC-7, Doctor Who wrote:
    On Fri, 3 Sep 2021 09:32:27 +0200, "Dmitry A. Kazakov" <mai...@dmitry-kazakov.de> wrote:

    On 2021-09-03 00:19, Randy Brukardt wrote:
    "Dmitry A. Kazakov" <mai...@dmitry-kazakov.de> wrote in message
    news:sgol48$r20$1...@gioia.aioe.org...
    ...
    Most mail servers do not accept unencrypted connections.

    That's news to me, as my mail server (you know, the one that runs
    Ada-Comment and the other ARG lists) doesn't support encrypted connections.
    I don't have any problem sending to GMail (I send copies of most of my
    personal mail there). Something else must be wrong.

    The question is with what settings. There are hundreds of combinations
    of Port x unencrypted|StartTLS|TLS x authentication method.

    The port 465 was intended for TLS, then it was depreciated. Then they >introduced other ports. Legacy mail servers pissed that all on etc.

    From experience, getting a SMTP client working is real pain.
    he is better off using his own provider's mail server on port 25, it
    will accept username/password as authentication.
    Hi all,

    thank you for your comments and responses.

    I tried changing the port number to 25, using the default port number in the SMTP.Client.Initialize procedure, and using other port numbers such as 587. I even tried just initializing the SMT server and sending the email (without authentication) as
    indicated in https://docs.adacore.com/aws-docs/aws/working_with_mails.html.

    In all cases, I get the following error:

    Can't send message :530 5.7.0 Must issue a STARTTLS command first. u7sm5705829pju.13 - gsmtp

    The problem is I don't know how to send the STARTTLS command with AWS. Anyone know how?

    My past experience was mostly with real-time embedded systems, so I don't have a lot of experience with email servers. I didn't expect this to be so difficult. Since this was mostly a toy to learn Ada, I may move on to other aspects of Ada for now.

    Thanks for all your comments.
    --Juan

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dmitry A. Kazakov@21:1/5 to Juan Rayas on Fri Sep 3 20:31:06 2021
    On 2021-09-03 20:11, Juan Rayas wrote:

    In all cases, I get the following error:

    Can't send message :530 5.7.0 Must issue a STARTTLS command first. u7sm5705829pju.13 - gsmtp

    The problem is I don't know how to send the STARTTLS command with AWS. Anyone know how?

    There should be some settings parameter instructing the client to send
    StartTLS right after it connects to the server. At least in my SMTP implementation it is so.

    But again, either port 587 or StartTLS, both require TLS, e.g. over
    GNUTLS or else OpenSSL.

    You need to tell AWS that you are going to use one them, specify the certificates, the keys etc. You must really read the AWS documentation regarding secure connections.

    --
    Regards,
    Dmitry A. Kazakov
    http://www.dmitry-kazakov.de

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Doctor Who@21:1/5 to juan.m.rayas@gmail.com on Fri Sep 3 21:33:15 2021
    On Fri, 3 Sep 2021 11:11:41 -0700 (PDT), Juan Rayas
    <juan.m.rayas@gmail.com> wrote:

    On Friday, September 3, 2021 at 1:59:33 AM UTC-7, Doctor Who wrote:
    On Fri, 3 Sep 2021 09:32:27 +0200, "Dmitry A. Kazakov"
    <mai...@dmitry-kazakov.de> wrote:

    On 2021-09-03 00:19, Randy Brukardt wrote:
    "Dmitry A. Kazakov" <mai...@dmitry-kazakov.de> wrote in message
    news:sgol48$r20$1...@gioia.aioe.org...
    ...
    Most mail servers do not accept unencrypted connections.

    That's news to me, as my mail server (you know, the one that runs
    Ada-Comment and the other ARG lists) doesn't support encrypted connections.
    I don't have any problem sending to GMail (I send copies of most of my
    personal mail there). Something else must be wrong.

    The question is with what settings. There are hundreds of combinations
    of Port x unencrypted|StartTLS|TLS x authentication method.

    The port 465 was intended for TLS, then it was depreciated. Then they
    introduced other ports. Legacy mail servers pissed that all on etc.

    From experience, getting a SMTP client working is real pain.
    he is better off using his own provider's mail server on port 25, it
    will accept username/password as authentication.
    Hi all,

    thank you for your comments and responses.

    I tried changing the port number to 25, using the default port number in the SMTP.Client.Initialize procedure, and using other port numbers such as 587. I even tried just initializing the SMT server and sending the email (without authentication) as
    indicated in https://docs.adacore.com/aws-docs/aws/working_with_mails.html.

    In all cases, I get the following error:

    Can't send message :530 5.7.0 Must issue a STARTTLS command first. u7sm5705829pju.13 - gsmtp

    The problem is I don't know how to send the STARTTLS command with AWS. Anyone know how?

    My past experience was mostly with real-time embedded systems, so I don't have a lot of experience with email servers. I didn't expect this to be so difficult. Since this was mostly a toy to learn Ada, I may move on to other aspects of Ada for now.

    Thanks for all your comments.
    --Juan


    you have to change mail server:

    Isp :=
    SMTP.Client.Initialize
    ("smtp.gmail.com", Port => 465,
    Credential => Auth'Unchecked_Access);

    don't use gmail, use your provider mail server ...

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Juan Rayas@21:1/5 to Doctor Who on Fri Sep 3 13:29:47 2021
    On Friday, September 3, 2021 at 12:33:19 PM UTC-7, Doctor Who wrote:
    On Fri, 3 Sep 2021 11:11:41 -0700 (PDT), Juan Rayas
    <juan.m...@gmail.com> wrote:

    On Friday, September 3, 2021 at 1:59:33 AM UTC-7, Doctor Who wrote:
    On Fri, 3 Sep 2021 09:32:27 +0200, "Dmitry A. Kazakov"
    <mai...@dmitry-kazakov.de> wrote:

    On 2021-09-03 00:19, Randy Brukardt wrote:
    "Dmitry A. Kazakov" <mai...@dmitry-kazakov.de> wrote in message
    news:sgol48$r20$1...@gioia.aioe.org...
    ...
    Most mail servers do not accept unencrypted connections.

    That's news to me, as my mail server (you know, the one that runs
    Ada-Comment and the other ARG lists) doesn't support encrypted connections.
    I don't have any problem sending to GMail (I send copies of most of my >> >> personal mail there). Something else must be wrong.

    The question is with what settings. There are hundreds of combinations >> >of Port x unencrypted|StartTLS|TLS x authentication method.

    The port 465 was intended for TLS, then it was depreciated. Then they
    introduced other ports. Legacy mail servers pissed that all on etc.

    From experience, getting a SMTP client working is real pain.
    he is better off using his own provider's mail server on port 25, it
    will accept username/password as authentication.
    Hi all,

    thank you for your comments and responses.

    I tried changing the port number to 25, using the default port number in the SMTP.Client.Initialize procedure, and using other port numbers such as 587. I even tried just initializing the SMT server and sending the email (without authentication) as
    indicated in https://docs.adacore.com/aws-docs/aws/working_with_mails.html.

    In all cases, I get the following error:

    Can't send message :530 5.7.0 Must issue a STARTTLS command first. u7sm5705829pju.13 - gsmtp

    The problem is I don't know how to send the STARTTLS command with AWS. Anyone know how?

    My past experience was mostly with real-time embedded systems, so I don't have a lot of experience with email servers. I didn't expect this to be so difficult. Since this was mostly a toy to learn Ada, I may move on to other aspects of Ada for now.

    Thanks for all your comments.
    --Juan
    you have to change mail server:
    Isp :=
    SMTP.Client.Initialize
    ("smtp.gmail.com", Port => 465,
    Credential => Auth'Unchecked_Access);
    don't use gmail, use your provider mail server ...
    Hi all,

    I changed the SMTP server to my ISP server (instead of Gmail), and changed the port back to 25. This worked!!

    Thanks for your help and suggestions. Now on to learning other aspects of Ada.

    --Juan

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Simon Wright@21:1/5 to Juan Rayas on Fri Sep 3 21:35:11 2021
    Juan Rayas <juan.m.rayas@gmail.com> writes:

    Isp :=
    SMTP.Client.Initialize
    ("smtp.gmail.com", Port => 465,
    Credential => Auth'Unchecked_Access);

    I succeed sending mail via gmail.com using port 587.

    No useful further details on encryption - this was for the membership
    d/b for a small club, and it's in Python/sqlite.

    self.server = smtplib.SMTP(host=self.server_details['host'],
    port=self.server_details['port'])
    self.server.ehlo()
    self.server.starttls()
    self.server.ehlo()
    self.server.login\
    (user=server_details['user'],
    password=keyring.get_password\
    ('u3a-email', server_details['user']))

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dmitry A. Kazakov@21:1/5 to Simon Wright on Fri Sep 3 23:13:38 2021
    On 2021-09-03 22:35, Simon Wright wrote:
    Juan Rayas <juan.m.rayas@gmail.com> writes:

    Isp :=
    SMTP.Client.Initialize
    ("smtp.gmail.com", Port => 465,
    Credential => Auth'Unchecked_Access);

    I succeed sending mail via gmail.com using port 587.

    No useful further details on encryption - this was for the membership
    d/b for a small club, and it's in Python/sqlite.

    GNUTLS and OpenSSL have ways to tell to use the system certificates.
    E.g. if your Python application uses GNUTLS it would call

    gnutls_certificate_set_x509_system_trust

    and that should be enough to make successful handshaking afterwards.

    self.server = smtplib.SMTP(host=self.server_details['host'],
    port=self.server_details['port'])
    self.server.ehlo()
    self.server.starttls()

    Here it switches transport to GNUTLS or OpenSSL and these perform TLS handshaking. The following commands run over encrypted channel.

    But with the port 587 you should actually begin with TLS straight away. StartTLS is for servers which allow both secure and insecure
    connections. This is usually the port 465. If you are OK with no
    encryption you greet with HELO and then proceed with login. If you want
    a secure connection you greet with EHLO and then send StartTLS.

    self.server.ehlo()
    self.server.login\
    (user=server_details['user'],
    password=keyring.get_password\
    ('u3a-email', server_details['user']))

    This is very low-level. AWS design is far better, IMO.

    --
    Regards,
    Dmitry A. Kazakov
    http://www.dmitry-kazakov.de

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)