{"record":{"id":"4c0786934bcbfffc","repo":"usememos/memos","slug":"smtp-host-is-required","errorCode":null,"errorMessage":"SMTP host is required","messagePattern":"SMTP host is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/email/config.go","lineNumber":33,"sourceCode":"\tSMTPPort int\n\t// SMTPUsername is the SMTP authentication username (usually the email address)\n\tSMTPUsername string\n\t// SMTPPassword is the SMTP authentication password or app-specific password\n\tSMTPPassword string\n\t// FromEmail is the email address that will appear in the \"From\" field\n\tFromEmail string\n\t// FromName is the display name that will appear in the \"From\" field\n\tFromName string\n\t// UseTLS enables STARTTLS encryption (recommended for port 587)\n\tUseTLS bool\n\t// UseSSL enables SSL/TLS encryption (for port 465)\n\tUseSSL bool\n}\n\n// Validate checks if the configuration is valid.\nfunc (c *Config) Validate() error {\n\tif c.SMTPHost == \"\" {\n\t\treturn errors.New(\"SMTP host is required\")\n\t}\n\tif c.SMTPPort <= 0 || c.SMTPPort > 65535 {\n\t\treturn errors.New(\"SMTP port must be between 1 and 65535\")\n\t}\n\tif c.FromEmail == \"\" {\n\t\treturn errors.New(\"from email is required\")\n\t}\n\treturn nil\n}\n\n// GetServerAddress returns the SMTP server address in the format \"host:port\".\nfunc (c *Config) GetServerAddress() string {\n\treturn fmt.Sprintf(\"%s:%d\", c.SMTPHost, c.SMTPPort)\n}\n","sourceCodeStart":15,"sourceCodeEnd":48,"githubUrl":"https://github.com/usememos/memos/blob/14d757ce1fb31c78590f374bc042f8dbedbc20d7/internal/email/config.go#L15-L48","documentation":"Returned by Config.Validate() in internal/email/config.go when SMTPHost is the empty string. The SMTP client cannot dial GetServerAddress() (\"host:port\") without a host, so validation fails fast before any connection attempt. It is a pure configuration error: the mailer was constructed without a host.","triggerScenarios":"Instantiating email.NewClient / sending mail with a Config whose SMTPHost was never set — e.g., SMTP system setting empty in the Memos admin UI, or an environment/config loader defaulting host to \"\". First surfaces on the first email send (e.g., a memo notification or test email) or at config validation time.","commonSituations":"Fresh install where the SMTP settings were never filled; deployment where the SMTP_HOST env var name differs from what the loader expects; adding email notifications to a stack/compose file but leaving host blank; YAML/JSON config with a typo'd key so the field stays zero-valued.","solutions":["Set the SMTP host in Settings > SMTP (e.g., smtp.example.com) or the equivalent config source, then re-validate.","Check that the config key actually maps to Config.SMTPHost (typo/case mismatch in env or YAML keys).","Call Validate() early at startup or after config load so this surfaces before the first send attempt.","Confirm the rest of the config passes too (port 1-65535, FromEmail non-empty) since Validate checks all three."],"exampleFix":"// before\ncfg := email.Config{SMTPPort: 587, FromEmail: \"noreply@example.com\"}\n\n// after\ncfg := email.Config{SMTPHost: \"smtp.example.com\", SMTPPort: 587, FromEmail: \"noreply@example.com\"}\nif err := cfg.Validate(); err != nil {\n  return err\n}","handlingStrategy":"validation","validationCode":"// Go — validate before constructing the mailer\nif strings.TrimSpace(cfg.SMTPHost) == \"\" {\n  return errors.New(\"SMTP host missing: set it in settings or config before enabling mail\")\n}\nif err := cfg.Validate(); err != nil {\n  return err\n}","typeGuard":null,"tryCatchPattern":"if err := cfg.Validate(); err != nil {\n  if errors.Is(err, email.ErrHostRequired) { /* if sentinel introduced */ }\n  return errors.Wrap(err, \"invalid SMTP config\")\n}","preventionTips":["Run Config.Validate() at startup or settings-save time, not only on first send.","Fail the admin form when host is blank instead of persisting an unusable config.","Integration-test config loading with the exact env/YAML keys you deploy."],"tags":["smtp","email","configuration","validation","go"],"backgroundTag":null,"analyzedSha":"14d757ce1fb31c78590f374bc042f8dbedbc20d7","analyzedAt":"2026-08-15T09:27:36.538Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}