Swift-SMTP icon indicating copy to clipboard operation
Swift-SMTP copied to clipboard

Feature/107 no auth connect

Open sbeitzel opened this issue 2 years ago • 5 comments

Fix issue #107 by only trying to authenticate if the server advertises the AUTH extended capability.

Description

During socket initialization, we will check to see if the server even supports AUTH before we attempt to perform a login.

Motivation and Context

Not every SMTP server requires authentication. If you try to use this library to connect to one such, you will have no luck. A trivial real-world use case for this would be a docker container that's running an open SMTP relay but which is only accessible to an application server running in a different container. It seems strange for an SMTP client library to enforce a server's authentication policy, and to limit itself to connecting only to servers which support an optional command.

Fixes issue #107

How Has This Been Tested?

Running an open, "dummy" SMTP server locally, I tried to connect an SMTPSocket to it. Initially, since the server did not advertise an AUTH capability, this threw an exception. After the change, the connection succeeded.

Checklist:

  • [x] I have submitted a CLA form
  • [x] If applicable, I have added tests to cover my changes.

sbeitzel avatar Jan 15 '22 20:01 sbeitzel

Thanks for the submission @sbeitzel and for your review @mbarnach. Cursory glance looks okay to me, I'll aim to look more closely this weekend if that's okay for you. Please don't worry if I close/open the PR, which I'll probably have to do to ensure travis is integrated correctly. It might take a little extra time since I just realized something happened to the server I was using as a docker registry and will have to rebuild it.

dannys42 avatar Jan 26 '22 01:01 dannys42

@sbeitzel I had to make some changes to CI, would you mind rebasing?

dannys42 avatar Feb 07 '22 04:02 dannys42

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

sonarcloud[bot] avatar Feb 12 '22 00:02 sonarcloud[bot]

In some cases a server can support authenticated and unauthenticated connections. Does this change support unauthenticated connections to servers which support both?

Not a contribution

Juice805 avatar Feb 23 '24 21:02 Juice805

Without a test to prove it, I can only say, "Sure, should do." Note that the calling code still needs to set up the SMTP instance, and it's the initializer of SMTP that sets up authentication. So, the calling code needs to be aware of whether it's trying to authenticate or not.

sbeitzel avatar Feb 23 '24 21:02 sbeitzel