knadh/listmonk · error

unknown SMTP auth type '%s'

Error message

unknown SMTP auth type '%s'

What it means

New() builds an SMTP messenger and maps s.AuthProtocol to an smtp/smtppool auth mechanism. Only "plain", "login", and ""/"none" are recognized; any other value falls into the default branch and returns this error instead of a messenger.

Source

Thrown at internal/messenger/email/email.go:83

	e := &Emailer{
		name:  name,
		pools: make(map[string][]*Server),
	}

	for _, srv := range servers {
		s := srv

		var auth smtp.Auth
		switch s.AuthProtocol {
		case "cram":
			auth = smtp.CRAMMD5Auth(s.Username, s.Password)
		case "plain":
			auth = smtp.PlainAuth("", s.Username, s.Password, s.Host)
		case "login":
			auth = &smtppool.LoginAuth{Username: s.Username, Password: s.Password}
		case "", "none":
		default:
			return nil, fmt.Errorf("unknown SMTP auth type '%s'", s.AuthProtocol)
		}
		s.Opt.Auth = auth

		// TLS config.
		s.Opt.SSL = smtppool.SSLNone
		if s.TLSType != "none" {
			s.TLSConfig = &tls.Config{}
			if s.TLSSkipVerify {
				s.TLSConfig.InsecureSkipVerify = s.TLSSkipVerify
			} else {
				s.TLSConfig.ServerName = s.Host
			}

			// SSL/TLS, not STARTTLS.
			switch s.TLSType {
			case "TLS":
				s.Opt.SSL = smtppool.SSLTLS
			case "STARTTLS":

View on GitHub (pinned to 670c01717d)

Solutions

  1. Set AuthProtocol to one of: "plain", "login", or ""/"none" (empty means no auth)
  2. Check for case mismatches — values are matched exactly, lowercase
  3. If you need CRAM-MD5/OAuth2, add a case to the switch in New() mapping to the appropriate smtp auth type

Example fix

// before
s.AuthProtocol = "PLAIN"
// after
s.AuthProtocol = "plain"
Defensive patterns

Strategy: validation

Validate before calling

allowed := map[string]bool{"plain": true, "login": true, "": true, "none": true}
if !allowed[settings.AuthProtocol] {
    return fmt.Errorf("AuthProtocol must be plain|login|none, got %q", settings.AuthProtocol)
}

Try / catch

if _, err := email.New(settings); err != nil {
    if strings.Contains(err.Error(), "unknown SMTP auth type") {
        // fall back to defaults or surface a config error to the user
    }
}

Prevention

When it happens

Trigger: Calling New (directly or via initSMTPMessengers or TestSMTPSettings) with SMTPSettings.AuthProtocol set to any string other than "plain", "login", "", or "none" — e.g. "cram-md5", "oauth2", "PLAIN" (case-sensitive).

Common situations: Typo in the SMTP auth setting in config/UI; uppercase value like "PLAIN" since the switch is case-sensitive; copying auth settings from another mailer that uses different names (e.g. "cram-md5"); newer auth schemes not supported by this codebase.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of knadh/listmonk@670c01717d (2026-09-01). Data as JSON: /api/errors/ef6c51e103bd6e63. Report an issue: GitHub.