diff --git a/.chglog/CHANGELOG.tpl.md b/.chglog/CHANGELOG.tpl.md new file mode 100755 index 0000000..9d02fa2 --- /dev/null +++ b/.chglog/CHANGELOG.tpl.md @@ -0,0 +1,47 @@ +# Changelog + +Notable changes to Mailpit will be documented in this file. + +{{ if .Versions -}} +{{ if .Unreleased.CommitGroups -}} +## [Unreleased] + +{{ if .Unreleased.CommitGroups -}} +{{ range .Unreleased.CommitGroups -}} +### {{ .Title }} +{{ range .Commits -}} +- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }} +{{ end }} +{{ end }} +{{ end -}} +{{ end -}} +{{ end -}} + +{{ range .Versions }} +{{- if .CommitGroups -}} +## [{{ .Tag.Name }}] + +{{ if .NoteGroups -}} +{{ range .NoteGroups -}} +### {{ .Title }} +{{ range .Notes }} +{{ .Body }} +{{ end -}} +{{ end }} +{{ end -}} +{{ end -}} + +{{ range .CommitGroups -}} +### {{ .Title }} +{{ range .Commits -}} +- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }} +{{ end }} +{{ end }} + +{{- if .MergeCommits -}} +### Pull Requests +{{ range .MergeCommits -}} +- {{ .Header }} +{{ end }} +{{ end }} +{{ end -}} diff --git a/.chglog/RELEASE.tpl.md b/.chglog/RELEASE.tpl.md new file mode 100755 index 0000000..a8ce8ae --- /dev/null +++ b/.chglog/RELEASE.tpl.md @@ -0,0 +1,12 @@ +{{ if .Versions -}} +{{ range .Versions }} +{{- if .CommitGroups -}} +{{ range .CommitGroups -}} +### {{ .Title }} +{{ range .Commits -}} +- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }} +{{ end }} +{{ end -}} +{{ end -}} +{{ end -}} +{{ end -}} diff --git a/.chglog/config.yml b/.chglog/config.yml new file mode 100755 index 0000000..0b5c0aa --- /dev/null +++ b/.chglog/config.yml @@ -0,0 +1,46 @@ +style: github +template: CHANGELOG.tpl.md +info: + title: CHANGELOG + repository_url: https://github.com/axllent/mailpit +options: + commits: + # filters: + # Type: + # - feat + # - fix + # - perf + # - refactor + commit_groups: + title_maps: + feature: Feature + fix: Fix + # perf: Performance Improvements + # refactor: Code Refactoring + sort_by: Custom + title_order: + - Feature + - Chore + - UI + - API + - Libs + - Docker + - Security + - Fix + - Bugfix + - Docs + - Swagger + - Build + - Testing + - Test + - Tests + - Pull Requests + header: + pattern: "^(\\w*)(?:\\(([\\w\\$\\.\\-\\*\\s]*)\\))?\\:\\s(.*)$" + pattern_maps: + - Type + - Scope + - Subject + notes: + keywords: + - BREAKING CHANGE diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..0eb8a39 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,42 @@ +# Changelog + +Notable changes to Mailpit will be documented in this file. + +## [v0.0.6] + +### Chore +- Automatically generate email headers if input does not contain valid email headers ([#10](https://github.com/axllent/mailpit/issues/10)) +- Add changelog + + +## [v0.0.5] + +### Feature +- Add Message-Id and Date headers (if missing) + +### Fix +- Prevent additional "\r\n.\r\n" after DATA is over ([#10](https://github.com/axllent/mailpit/issues/10)) + +### Pull Requests +- Merge pull request [#9](https://github.com/axllent/mailpit/issues/9) from axllent/dependabot/github_actions/wangyoucao577/go-release-action-1.51 +- Merge pull request [#8](https://github.com/axllent/mailpit/issues/8) from axllent/dependabot/github_actions/wangyoucao577/go-release-action-1.50 +- Merge pull request [#7](https://github.com/axllent/mailpit/issues/7) from axllent/dependabot/github_actions/wangyoucao577/go-release-action-1.49 +- Merge pull request [#6](https://github.com/axllent/mailpit/issues/6) from axllent/dependabot/github_actions/wangyoucao577/go-release-action-1.46 +- Merge pull request [#4](https://github.com/axllent/mailpit/issues/4) from axllent/dependabot/github_actions/github/codeql-action-3 +- Merge pull request [#5](https://github.com/axllent/mailpit/issues/5) from axllent/dependabot/github_actions/wangyoucao577/go-release-action-1.41 +- Merge pull request [#3](https://github.com/axllent/mailpit/issues/3) from axllent/dependabot/github_actions/actions/stale-9.0.0 + + +### Pull Requests +- Merge pull request [#2](https://github.com/axllent/mailpit/issues/2) from axllent/dependabot/github_actions/actions/checkout-4 +- Merge pull request [#1](https://github.com/axllent/mailpit/issues/1) from axllent/dependabot/github_actions/wangyoucao577/go-release-action-1.40 + + +## [v0.0.3] + +### Feature +- Add optional logging + + + + diff --git a/README.md b/README.md index 2cd21d1..a110f06 100644 --- a/README.md +++ b/README.md @@ -14,21 +14,22 @@ It was created primarily for use in Docker containers. Whilst there are many dif - Static drop-in replacement for sendmail - Configurable SMTP relay server, STARTTLS with PLAIN, LOGIN and CRAM-MD5 support - SMTP on standard input (`sendmail -bs`) +- Auto-generates (if missing from input) `Message-Id`, `From` & `Date` headers ## Installation - Static binaries can be found on the [releases](https://github.com/axllent/sndmail/releases/latest) -- Copy or symlink the `sndmail` executable to `/usr/sbin/sendmail` +- Copy or symlink the `sndmail` executable from `/usr/sbin/sendmail` - Copy the `sndmail.conf.example` to `/etc/sndmail.conf` making any necessary edits to adjust to your SMTP relay server ### Install via bash script (Linux & Mac) +**Warning**: This will delete any existing /usr/sbin/sendmail! + Linux & Mac users can install it directly via: ```bash sudo bash < <(curl -sL https://raw.githubusercontent.com/axllent/sndmail/develop/install.sh) ``` - -**Warning**: This will delete any existing /usr/sbin/sendmail diff --git a/cmd/mailer.go b/cmd/mailer.go index ee2c679..4d563b5 100644 --- a/cmd/mailer.go +++ b/cmd/mailer.go @@ -17,7 +17,7 @@ import ( // SMTP wrapper will send and optionally log the transaction func smtpWrapper(from string, to []string, message []byte) error { - msg, err := injectHeaders(message) + msg, err := injectMissingHeaders(message, from) if err != nil { return err } @@ -140,11 +140,16 @@ func dataWithResponse(c *smtp.Client, msg []byte) (int, string, error) { return c.Text.ReadResponse(250) } -// Inject Message-Id and Date if missing -func injectHeaders(body []byte) ([]byte, error) { +// Inject Message-Id and Date if missing. The From address is also +// optionally injected if missing. +func injectMissingHeaders(body []byte, from string) ([]byte, error) { msg, err := mail.ReadMessage(bytes.NewReader(body)) if err != nil { - return nil, err + // create blank message so lookups don't fail + msg = &mail.Message{} + + // inject a new blank line before body + body = append([]byte(fmt.Sprintf("\r\n")), body...) } // add message ID if missing @@ -159,6 +164,11 @@ func injectHeaders(body []byte) ([]byte, error) { body = append([]byte("Date: "+now+"\r\n"), body...) } + // set From header is missing + if msg.Header.Get("From") == "" { + body = append([]byte("From: <"+from+">\r\n"), body...) + } + return body, nil } diff --git a/sndmail.conf.example b/sndmail.conf.example index 6b079e5..db53e28 100644 --- a/sndmail.conf.example +++ b/sndmail.conf.example @@ -31,7 +31,7 @@ ### Default: empty #auth-pass = password -### Log file - to log, get the absolite path to a logfile. The file must be +### Log file - to log, get the absolute path to a logfile. The file must be ### writable by all users using sndmail otherwise logging will silently fail. ### Default: empty #log-file = /var/log/mail.log