xhit/go-simple-mail

Exporting authType type

ayoubfaouzi opened this issue · 3 comments

Hello @xhit

First, thanks for the package !

Would it make sense to make the type type authType public like what you have done for Encryption?

So in a method which creates the SMTP client could take the authType as string then cast it to authType.

Cheers.

xhit commented

Yes, make sense that change.

If you want to share a PR I will take a look in next hours. If not, I will commit the changes this night.

xhit commented

Done. Now you can use a func like this:

func AuthTypeFromString(authType string) (mail.AuthType, error) {
	switch {
	case strings.EqualFold(authType, "none"):
		return mail.AuthNone, nil
	case strings.EqualFold(authType, "plain"):
		return mail.AuthPlain, nil
	case strings.EqualFold(authType, "login"):
		return mail.AuthLogin, nil
	case strings.EqualFold(authType, "cram-md5"):
		return mail.AuthCRAMMD5, nil
	}

	return mail.AuthNone, fmt.Errorf(`invalid authentication type "%s"`, authType)
}

Thank you so much !