kaisellgren / mailer

Compose and send emails from Dart. Supports file attachments, HTML emails and multiple transport methods.
MIT License
168 stars 88 forks source link

Optional _doAuthentication() #234

Closed pst9354 closed 1 year ago

pst9354 commented 1 year ago

Hi,

We have a mail server that doesn't allow authentication (ip-locked, behind firewall, etc).

I just made a quick and dirty change to fix this issue (see below). Is there something you could support for the next release?


In smtp_client.dart (line 129)

Original:

    // Authenticate
      await _doAuthentication(c);

Our code:

    // Authenticate
    bool bSkip = false;
    if (smtpServer.username == null) {
      bSkip = true;
    } else {
      if (smtpServer.username!.isEmpty) {
        bSkip = true;
      }
    }

    if (!bSkip) {
      await _doAuthentication(c);
    }
close2 commented 1 year ago

This should already work with the existing code. _doAuthentication does check, if username and password is set:

  if (c.server.username != null && c.server.password != null) {
    loginResp = await _doAuthLogin(c);
  } else if (c.server.xoauth2Token != null) {
    loginResp = await _doAuthXoauth2(c);
  }

The difference to your code is, that you skip the authentication also if the username isEmpty.

I would need to research if SMTP allows empty usernames. If not, adding the check is of course no problem.

(To avoid unnecessary research, I'll wait for your feedback, if this really is your problem.)

pst9354 commented 1 year ago

Thanks for the above. Setting username and password to null, worked out fine.