72 Commits

Author SHA1 Message Date
Bernhard Froehlich
c21c13cc7a Remove i386 from release builds 2022-05-01 11:23:56 +00:00
Bernhard Fröhlich
1617155f1e Remove service names from readme 2022-04-30 08:10:21 +02:00
Bernhard Fröhlich
81ea0c7944 Merge pull request #69 from decke/dependabot/github_actions/github/codeql-action-2
Bump github/codeql-action from 1 to 2
2022-04-26 14:33:39 +02:00
Bernhard Fröhlich
d9a09a20da Merge pull request #70 from decke/dependabot/github_actions/wangyoucao577/go-release-action-1.28
Bump wangyoucao577/go-release-action from 1.26 to 1.28
2022-04-26 14:33:04 +02:00
dependabot[bot]
d5d4e7a821 Bump wangyoucao577/go-release-action from 1.26 to 1.28
Bumps [wangyoucao577/go-release-action](https://github.com/wangyoucao577/go-release-action) from 1.26 to 1.28.
- [Release notes](https://github.com/wangyoucao577/go-release-action/releases)
- [Commits](https://github.com/wangyoucao577/go-release-action/compare/v1.26...v1.28)

---
updated-dependencies:
- dependency-name: wangyoucao577/go-release-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-04-26 10:17:49 +00:00
dependabot[bot]
77ab4485b2 Bump github/codeql-action from 1 to 2
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 1 to 2.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/v1...v2)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-04-26 10:17:46 +00:00
Bernhard Froehlich
ce97293e33 Update Go crypto and sys dependencies 2022-04-25 15:06:32 +00:00
Bernhard Froehlich
5cd81cd7e4 smtp: gofmt main repo
Merge from net/smtp/smtp.go

Obtained from:	19309779ac5e2f5a2fd3cbb34421dafb2855ac21
2022-04-25 15:00:57 +00:00
Bernhard Froehlich
62bb2becbc smtp: gofmt -w -r 'interface{}->any' src
Merge from net/smtp/smtp.go

Obtained from:	2580d0e08d5e9f979b943758d3c49877fb2324cb
2022-04-25 14:58:09 +00:00
Bernhard Froehlich
a2826e949e Regenerate go.mod for go 1.18 2022-04-25 14:42:23 +00:00
Bernhard Froehlich
64872c0bea Bump Go version to 1.18 for release and CI jobs 2022-04-25 14:37:23 +00:00
Bernhard Froehlich
cdc4e572db smtp: use bytes.Cut, strings.Cut
Merge from net/smtp/smtp.go

Obtained from:		4d8db00641cc9ff4f44de7df9b8c4f4a4f9416ee
2022-04-25 14:30:43 +00:00
Bernhard Froehlich
5e78bbe643 Improve remotes documentation in config 2022-04-25 14:19:31 +00:00
Javi
b134e426d7 Propagate the error to the client if the external command fails (#40)
This change makes the external command code return a generic 554 error to the SMTP client if the external command fails, so it knows sending failed and can retry.
2022-04-25 15:52:12 +02:00
Bernhard Fröhlich
9c230182da Merge pull request #68 from decke/dependabot/go_modules/github.com/stretchr/testify-1.7.1
Bump github.com/stretchr/testify from 1.7.0 to 1.7.1
2022-04-25 15:42:34 +02:00
dependabot[bot]
39b8e01226 Bump github.com/stretchr/testify from 1.7.0 to 1.7.1
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.7.0 to 1.7.1.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.7.0...v1.7.1)

---
updated-dependencies:
- dependency-name: github.com/stretchr/testify
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-04-25 10:09:05 +00:00
Bernhard Fröhlich
bf8c222ac1 Merge pull request #63 from markgardner/master
Allow config to have multiple remotes.
2022-04-24 19:45:34 +02:00
Mark Gardner
875264837e add test coverage for scheme validation 2022-04-21 11:39:41 -05:00
Mark Gardner
32d0206af0 throw an error if the remote is configured for starttls and the server does not have the extension 2022-04-21 11:29:15 -05:00
Mark Gardner
b7f3701502 Add missing default port for starttls and validate scheme to ensure support 2022-04-21 11:28:48 -05:00
Mark Gardner
cf927508dd Improve sample config to be more accurate 2022-04-21 11:28:16 -05:00
Mark Gardner
4221919689 Allow config to have multiple remotes.
This will enable development teams to test emails from
a system like mailcatcher while also having the email
delivered to the indented mailbox.
2022-04-21 10:52:03 -05:00
Bernhard Fröhlich
4f1148d77b Merge pull request #67 from decke/dependabot/github_actions/wangyoucao577/go-release-action-1.26
Bump wangyoucao577/go-release-action from 1.25 to 1.26
2022-04-16 19:23:31 +02:00
dependabot[bot]
32c43efd0c Bump wangyoucao577/go-release-action from 1.25 to 1.26
Bumps [wangyoucao577/go-release-action](https://github.com/wangyoucao577/go-release-action) from 1.25 to 1.26.
- [Release notes](https://github.com/wangyoucao577/go-release-action/releases)
- [Commits](https://github.com/wangyoucao577/go-release-action/compare/v1.25...v1.26)

---
updated-dependencies:
- dependency-name: wangyoucao577/go-release-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-04-15 10:05:45 +00:00
Bernhard Fröhlich
362a64dd8a Merge pull request #65 from decke/dependabot/github_actions/actions/checkout-3
Bump actions/checkout from 2.4.0 to 3
2022-03-02 21:47:04 +01:00
dependabot[bot]
bf58b2b4c8 Bump actions/checkout from 2.4.0 to 3
Bumps [actions/checkout](https://github.com/actions/checkout) from 2.4.0 to 3.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2.4.0...v3)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-03-02 10:07:48 +00:00
Bernhard Fröhlich
ed13816dcd Merge pull request #64 from decke/dependabot/github_actions/actions/setup-go-3
Bump actions/setup-go from 2.2.0 to 3
2022-03-01 14:36:05 +01:00
dependabot[bot]
dd7905e60e Bump actions/setup-go from 2.2.0 to 3
Bumps [actions/setup-go](https://github.com/actions/setup-go) from 2.2.0 to 3.
- [Release notes](https://github.com/actions/setup-go/releases)
- [Commits](https://github.com/actions/setup-go/compare/v2.2.0...v3)

---
updated-dependencies:
- dependency-name: actions/setup-go
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-03-01 10:07:35 +00:00
Bernhard Fröhlich
5076988ddf Merge pull request #59 from decke/dependabot/github_actions/wangyoucao577/go-release-action-1.25
Bump wangyoucao577/go-release-action from 1.24 to 1.25
2022-02-23 12:11:56 +01:00
dependabot[bot]
dafbc327aa Bump wangyoucao577/go-release-action from 1.24 to 1.25
Bumps [wangyoucao577/go-release-action](https://github.com/wangyoucao577/go-release-action) from 1.24 to 1.25.
- [Release notes](https://github.com/wangyoucao577/go-release-action/releases)
- [Commits](https://github.com/wangyoucao577/go-release-action/compare/v1.24...v1.25)

---
updated-dependencies:
- dependency-name: wangyoucao577/go-release-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-02-23 10:06:40 +00:00
Bernhard Fröhlich
48926964bf Merge pull request #58 from decke/dependabot/github_actions/actions/setup-go-2.2.0
Bump actions/setup-go from 2.1.5 to 2.2.0
2022-02-10 13:49:46 +01:00
dependabot[bot]
5757db3a37 Bump actions/setup-go from 2.1.5 to 2.2.0
Bumps [actions/setup-go](https://github.com/actions/setup-go) from 2.1.5 to 2.2.0.
- [Release notes](https://github.com/actions/setup-go/releases)
- [Commits](https://github.com/actions/setup-go/compare/v2.1.5...v2.2.0)

---
updated-dependencies:
- dependency-name: actions/setup-go
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-02-10 10:39:30 +00:00
Bernhard Fröhlich
a527a147be Merge pull request #56 from decke/dependabot/github_actions/wangyoucao577/go-release-action-1.24
Bump wangyoucao577/go-release-action from 1.23 to 1.24
2022-01-31 13:46:04 +01:00
dependabot[bot]
8c0a6aab20 Bump wangyoucao577/go-release-action from 1.23 to 1.24
Bumps [wangyoucao577/go-release-action](https://github.com/wangyoucao577/go-release-action) from 1.23 to 1.24.
- [Release notes](https://github.com/wangyoucao577/go-release-action/releases)
- [Commits](https://github.com/wangyoucao577/go-release-action/compare/v1.23...v1.24)

---
updated-dependencies:
- dependency-name: wangyoucao577/go-release-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-01-31 10:07:26 +00:00
Bernhard Fröhlich
5be2f3aa4b Merge pull request #55 from decke/dependabot/github_actions/wangyoucao577/go-release-action-1.23
Bump wangyoucao577/go-release-action from 1.22 to 1.23
2022-01-26 13:19:08 +01:00
dependabot[bot]
2b046297ea Bump wangyoucao577/go-release-action from 1.22 to 1.23
Bumps [wangyoucao577/go-release-action](https://github.com/wangyoucao577/go-release-action) from 1.22 to 1.23.
- [Release notes](https://github.com/wangyoucao577/go-release-action/releases)
- [Commits](https://github.com/wangyoucao577/go-release-action/compare/v1.22...v1.23)

---
updated-dependencies:
- dependency-name: wangyoucao577/go-release-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-01-26 10:06:33 +00:00
Bernhard Froehlich
f0d39401d4 Allow go build workflow for pull requests 2022-01-11 12:55:39 +00:00
Bernhard Fröhlich
b5fcf8e0bb Merge pull request #52 from Coronon/master
add: basic smtpd configuration options
2022-01-11 13:55:02 +01:00
Rubin Raithel
016ef762fb add: basic smtpd configuration options 2022-01-10 20:39:55 +01:00
Bernhard Fröhlich
6afc87968c Merge pull request #51 from decke/dependabot/github_actions/actions/setup-go-2.1.5
Bump actions/setup-go from 2.1.4 to 2.1.5
2021-12-22 11:43:16 +01:00
dependabot[bot]
b32b5690bf Bump actions/setup-go from 2.1.4 to 2.1.5
Bumps [actions/setup-go](https://github.com/actions/setup-go) from 2.1.4 to 2.1.5.
- [Release notes](https://github.com/actions/setup-go/releases)
- [Commits](https://github.com/actions/setup-go/compare/v2.1.4...v2.1.5)

---
updated-dependencies:
- dependency-name: actions/setup-go
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-12-22 10:08:04 +00:00
Bernhard Fröhlich
38aa05c9f4 Merge pull request #49 from NoUseFreak/add-skip-verify
Allow ignoring an insecure tls connection
2021-12-15 21:31:54 +01:00
Dries De Peuter
03d109ff8b feat: Add support for ignoring certs 2021-12-09 21:38:38 +01:00
Bernhard Fröhlich
6c691f3cea Merge pull request #48 from decke/dependabot/github_actions/wangyoucao577/go-release-action-1.22
Bump wangyoucao577/go-release-action from 1.21 to 1.22
2021-11-24 13:07:20 +01:00
dependabot[bot]
c6b5e244eb Bump wangyoucao577/go-release-action from 1.21 to 1.22
Bumps [wangyoucao577/go-release-action](https://github.com/wangyoucao577/go-release-action) from 1.21 to 1.22.
- [Release notes](https://github.com/wangyoucao577/go-release-action/releases)
- [Commits](https://github.com/wangyoucao577/go-release-action/compare/v1.21...v1.22)

---
updated-dependencies:
- dependency-name: wangyoucao577/go-release-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-11-24 10:06:54 +00:00
Bernhard Froehlich
0ee982ea31 Bump used Go versions to 1.17 2021-11-22 15:38:17 +00:00
Bernhard Fröhlich
287395ad91 Merge pull request #47 from alex1989hu/bump/chrj-smtpd-v031
Bump chrj/smtpd from 0.3.0 to 0.3.1
2021-11-22 11:39:33 +01:00
Alex Szakaly
3aecd3c6d6 Bump chrj/smtpd from 0.3.0 to 0.3.1
Fixes #44

Signed-off-by: Alex Szakaly <alex.szakaly@gmail.com>
2021-11-22 07:53:43 +01:00
Bernhard Fröhlich
f8960053e8 Merge pull request #46 from decke/dependabot/github_actions/wangyoucao577/go-release-action-1.21
Bump wangyoucao577/go-release-action from 1.20 to 1.21
2021-11-17 11:59:35 +01:00
dependabot[bot]
db5512d47b Bump wangyoucao577/go-release-action from 1.20 to 1.21
Bumps [wangyoucao577/go-release-action](https://github.com/wangyoucao577/go-release-action) from 1.20 to 1.21.
- [Release notes](https://github.com/wangyoucao577/go-release-action/releases)
- [Commits](https://github.com/wangyoucao577/go-release-action/compare/v1.20...v1.21)

---
updated-dependencies:
- dependency-name: wangyoucao577/go-release-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-11-16 10:07:49 +00:00
Bernhard Fröhlich
fd063ad879 Merge pull request #45 from decke/dependabot/github_actions/actions/checkout-2.4.0
Bump actions/checkout from 2.3.5 to 2.4.0
2021-11-03 11:49:27 +01:00
dependabot[bot]
85bdd060e3 Bump actions/checkout from 2.3.5 to 2.4.0
Bumps [actions/checkout](https://github.com/actions/checkout) from 2.3.5 to 2.4.0.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2.3.5...v2.4.0)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-11-03 10:05:55 +00:00
Bernhard Fröhlich
5be6165865 Merge pull request #43 from decke/dependabot/github_actions/actions/checkout-2.3.5
Bump actions/checkout from 2.3.4 to 2.3.5
2021-10-18 16:00:48 +02:00
dependabot[bot]
b64a34becf Bump actions/checkout from 2.3.4 to 2.3.5
Bumps [actions/checkout](https://github.com/actions/checkout) from 2.3.4 to 2.3.5.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2.3.4...v2.3.5)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-10-18 10:08:18 +00:00
Bernhard Fröhlich
a2ea5ab49e Merge pull request #42 from decke/dependabot/github_actions/wangyoucao577/go-release-action-1.20
Bump wangyoucao577/go-release-action from 1.19 to 1.20
2021-08-30 14:46:38 +02:00
dependabot[bot]
94957d944f Bump wangyoucao577/go-release-action from 1.19 to 1.20
Bumps [wangyoucao577/go-release-action](https://github.com/wangyoucao577/go-release-action) from 1.19 to 1.20.
- [Release notes](https://github.com/wangyoucao577/go-release-action/releases)
- [Commits](https://github.com/wangyoucao577/go-release-action/compare/v1.19...v1.20)

---
updated-dependencies:
- dependency-name: wangyoucao577/go-release-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-30 10:06:39 +00:00
Bernhard Fröhlich
a5db5e1ff5 Merge pull request #41 from decke/dependabot/github_actions/actions/setup-go-2.1.4
Bump actions/setup-go from 2.1.3 to 2.1.4
2021-08-26 13:14:35 +02:00
dependabot[bot]
94776b27d9 Bump actions/setup-go from 2.1.3 to 2.1.4
Bumps [actions/setup-go](https://github.com/actions/setup-go) from 2.1.3 to 2.1.4.
- [Release notes](https://github.com/actions/setup-go/releases)
- [Commits](https://github.com/actions/setup-go/compare/v2.1.3...v2.1.4)

---
updated-dependencies:
- dependency-name: actions/setup-go
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-26 10:06:19 +00:00
Bernhard Fröhlich
81bc7addc7 Merge pull request #39 from decke/dependabot/github_actions/wangyoucao577/go-release-action-1.19
Bump wangyoucao577/go-release-action from 1.18 to 1.19
2021-07-28 22:15:07 +02:00
dependabot[bot]
e9bfe53f18 Bump wangyoucao577/go-release-action from 1.18 to 1.19
Bumps [wangyoucao577/go-release-action](https://github.com/wangyoucao577/go-release-action) from 1.18 to 1.19.
- [Release notes](https://github.com/wangyoucao577/go-release-action/releases)
- [Commits](https://github.com/wangyoucao577/go-release-action/compare/v1.18...v1.19)

---
updated-dependencies:
- dependency-name: wangyoucao577/go-release-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-07-21 10:06:34 +00:00
Bernhard Fröhlich
32032c297c Merge pull request #38 from decke/dependabot/go_modules/github.com/google/uuid-1.3.0
Bump github.com/google/uuid from 1.2.0 to 1.3.0
2021-07-13 13:10:23 +02:00
dependabot[bot]
53e52de279 Bump github.com/google/uuid from 1.2.0 to 1.3.0
Bumps [github.com/google/uuid](https://github.com/google/uuid) from 1.2.0 to 1.3.0.
- [Release notes](https://github.com/google/uuid/releases)
- [Commits](https://github.com/google/uuid/compare/v1.2.0...v1.3.0)

---
updated-dependencies:
- dependency-name: github.com/google/uuid
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-07-13 10:06:56 +00:00
Bernhard Fröhlich
02810c0a50 Merge pull request #36 from decke/dependabot/github_actions/wangyoucao577/go-release-action-1.18
Bump wangyoucao577/go-release-action from 1.17 to 1.18
2021-05-26 14:36:30 +02:00
dependabot[bot]
6b21f52037 Bump wangyoucao577/go-release-action from 1.17 to 1.18
Bumps [wangyoucao577/go-release-action](https://github.com/wangyoucao577/go-release-action) from 1.17 to 1.18.
- [Release notes](https://github.com/wangyoucao577/go-release-action/releases)
- [Commits](https://github.com/wangyoucao577/go-release-action/compare/v1.17...v1.18)

Signed-off-by: dependabot[bot] <support@github.com>
2021-05-26 05:59:28 +00:00
Bernhard Fröhlich
544bd081ff Merge pull request #34 from decke/dependabot/github_actions/actions/checkout-2.3.4
Bump actions/checkout from 2 to 2.3.4
2021-05-12 08:41:49 +02:00
dependabot[bot]
6a28f939de Bump actions/checkout from 2 to 2.3.4
Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 2.3.4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2...v2.3.4)

Signed-off-by: dependabot[bot] <support@github.com>
2021-05-12 05:54:25 +00:00
Bernhard Fröhlich
f0392bdf09 Merge pull request #33 from benubois/command
Add external command support
2021-05-10 10:18:56 +02:00
Ben Ubois
3f627d3281 Move AddReceivedLine before further processing. 2021-05-08 11:56:28 -07:00
Ben Ubois
d8860fc917 Added external command support. 2021-05-07 14:08:10 -07:00
Bernhard Fröhlich
ebb53ea1b6 Merge pull request #30 from decke/dependabot/github_actions/wangyoucao577/go-release-action-v1.17
Bump wangyoucao577/go-release-action from v1.16 to v1.17
2021-04-13 20:13:18 +02:00
dependabot[bot]
a5ee525825 Bump wangyoucao577/go-release-action from v1.16 to v1.17
Bumps [wangyoucao577/go-release-action](https://github.com/wangyoucao577/go-release-action) from v1.16 to v1.17.
- [Release notes](https://github.com/wangyoucao577/go-release-action/releases)
- [Commits](https://github.com/wangyoucao577/go-release-action/compare/v1.16...1a87d97ce87db435508d150622a9ab5472db15ac)

Signed-off-by: dependabot[bot] <support@github.com>
2021-04-13 07:18:35 +00:00
Bernhard Froehlich
441a53cfd9 Fix code formatting with gofmt -s 2021-04-03 19:00:38 +00:00
14 changed files with 475 additions and 183 deletions

View File

@@ -25,7 +25,7 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
@@ -38,7 +38,7 @@ jobs:
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -49,7 +49,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
uses: github/codeql-action/autobuild@v2
# Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
@@ -63,4 +63,4 @@ jobs:
# make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v2

View File

@@ -1,5 +1,5 @@
name: Go
on: [push]
on: [push, pull_request]
jobs:
build:
@@ -7,14 +7,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.16
uses: actions/setup-go@v2.1.3
- name: Set up Go 1.18
uses: actions/setup-go@v3
with:
go-version: 1.16
go-version: 1.18
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v1
uses: actions/checkout@v3
- name: Get dependencies
run: |

View File

@@ -11,20 +11,20 @@ jobs:
strategy:
matrix:
goos: [freebsd, linux, windows]
goarch: ["386", amd64]
goarch: [amd64, arm64]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set APP_VERSION env
run: echo APP_VERSION=$(echo ${GITHUB_REF} | rev | cut -d'/' -f 1 | rev ) >> ${GITHUB_ENV}
- name: Set BUILD_TIME env
run: echo BUILD_TIME=$(date) >> ${GITHUB_ENV}
- uses: wangyoucao577/go-release-action@v1.16
- uses: wangyoucao577/go-release-action@v1.28
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
goversion: "https://golang.org/dl/go1.16.3.linux-amd64.tar.gz"
goversion: 1.18
extra_files: LICENSE README.md smtprelay.ini
ldflags: -s -w -X "main.appVersion=${{ env.APP_VERSION }}" -X "main.buildTime=${{ env.BUILD_TIME }}"

View File

@@ -16,8 +16,8 @@ configure.
My use case is simple. I need to send automatically generated mails from
cron via msmtp/sSMTP/dma, mails from various services and network printers
to GMail without giving away my GMail credentials to each device which
produces mail.
via a remote SMTP server without giving away my mail credentials to each
device which produces mail.
## Main features
@@ -26,6 +26,6 @@ produces mail.
* Checks for sender, receiver, client IP
* Authentication support with file (LOGIN, PLAIN)
* Enforce encryption for authentication
* Forwards all mail to a smarthost (GMail, MailGun or any other SMTP server)
* Forwards all mail to a smarthost (any SMTP server)
* Small codebase
* IPv6 support

120
config.go
View File

@@ -2,13 +2,14 @@ package main
import (
"flag"
"fmt"
"net"
"net/smtp"
"regexp"
"strings"
"time"
"github.com/vharitonsky/iniflags"
"github.com/sirupsen/logrus"
"github.com/vharitonsky/iniflags"
)
var (
@@ -27,6 +28,15 @@ var (
localCert = flag.String("local_cert", "", "SSL certificate for STARTTLS/TLS")
localKey = flag.String("local_key", "", "SSL private key for STARTTLS/TLS")
localForceTLS = flag.Bool("local_forcetls", false, "Force STARTTLS (needs local_cert and local_key)")
readTimeoutStr = flag.String("read_timeout", "60s", "Socket timeout for read operations")
readTimeout time.Duration
writeTimeoutStr = flag.String("write_timeout", "60s", "Socket timeout for write operations")
writeTimeout time.Duration
dataTimeoutStr = flag.String("data_timeout", "5m", "Socket timeout for DATA command")
dataTimeout time.Duration
maxConnections = flag.Int("max_connections", 100, "Max concurrent connections, use -1 to disable")
maxMessageSize = flag.Int("max_message_size", 10240000, "Max message size in bytes")
maxRecipients = flag.Int("max_recipients", 100, "Max RCPT TO calls for each envelope")
allowedNetsStr = flag.String("allowed_nets", "127.0.0.0/8 ::1/128", "Networks allowed to send mails")
allowedNets = []*net.IPNet{}
allowedSenderStr = flag.String("allowed_sender", "", "Regular expression for valid FROM EMail addresses")
@@ -34,12 +44,9 @@ var (
allowedRecipStr = flag.String("allowed_recipients", "", "Regular expression for valid TO EMail addresses")
allowedRecipients *regexp.Regexp
allowedUsers = flag.String("allowed_users", "", "Path to file with valid users/passwords")
remoteHost = flag.String("remote_host", "", "Outgoing SMTP server")
remoteUser = flag.String("remote_user", "", "Username for authentication on outgoing SMTP server")
remotePass = flag.String("remote_pass", "", "Password for authentication on outgoing SMTP server")
remoteAuthStr = flag.String("remote_auth", "none", "Auth method on outgoing SMTP server (none, plain, login)")
remoteAuth smtp.Auth
remoteSender = flag.String("remote_sender", "", "Sender e-mail address on outgoing SMTP server")
command = flag.String("command", "", "Path to pipe command")
remotesStr = flag.String("remotes", "", "Outgoing SMTP servers")
remotes = []*Remote{}
versionInfo = flag.Bool("version", false, "Show version information")
)
@@ -47,7 +54,6 @@ func localAuthRequired() bool {
return *allowedUsers != ""
}
func setupAllowedNetworks() {
for _, netstr := range splitstr(*allowedNetsStr, ' ') {
baseIP, allowedNet, err := net.ParseCIDR(netstr)
@@ -73,7 +79,7 @@ func setupAllowedNetworks() {
func setupAllowedPatterns() {
var err error
if (*allowedSenderStr != "") {
if *allowedSenderStr != "" {
allowedSender, err = regexp.Compile(*allowedSenderStr)
if err != nil {
log.WithField("allowed_sender", *allowedSenderStr).
@@ -82,7 +88,7 @@ func setupAllowedPatterns() {
}
}
if (*allowedRecipStr != "") {
if *allowedRecipStr != "" {
allowedRecipients, err = regexp.Compile(*allowedRecipStr)
if err != nil {
log.WithField("allowed_recipients", *allowedRecipStr).
@@ -92,47 +98,18 @@ func setupAllowedPatterns() {
}
}
func setupRemotes() {
logger := log.WithField("remotes", *remotesStr)
func setupRemoteAuth() {
logger := log.WithField("remote_auth", *remoteAuthStr)
// Remote auth disabled?
if *remoteAuthStr == "" || *remoteAuthStr == "none" {
if *remoteUser != "" {
logger.Fatal("remote_user given but not used")
}
if *remotePass != "" {
logger.Fatal("remote_pass given but not used")
}
// No auth; use empty default
return
}
// We need a username, password, and remote host
if *remoteUser == "" {
logger.Fatal("remote_user required but empty")
}
if *remotePass == "" {
logger.Fatal("remote_pass required but empty")
}
if *remoteHost == "" {
logger.Fatal("remote_auth without remote_host is pointless")
}
host, _, err := net.SplitHostPort(*remoteHost)
if *remotesStr != "" {
for _, remoteURL := range strings.Split(*remotesStr, " ") {
r, err := ParseRemote(remoteURL)
if err != nil {
logger.WithField("remote_host", *remoteHost).
Fatal("Invalid remote_host")
logger.Fatal(fmt.Sprintf("error parsing url: '%s': %v", remoteURL, err))
}
switch *remoteAuthStr {
case "plain":
remoteAuth = smtp.PlainAuth("", *remoteUser, *remotePass, host)
case "login":
remoteAuth = LoginAuth(*remoteUser, *remotePass)
default:
logger.Fatal("Invalid remote_auth type")
remotes = append(remotes, r)
}
}
}
@@ -150,7 +127,7 @@ func splitProto(s string) protoAddr {
}
return protoAddr{
protocol: s[0:idx],
address: s[idx+3 : len(s)],
address: s[idx+3:],
}
}
@@ -164,23 +141,60 @@ func setupListeners() {
"not allowed with non-TLS listener")
}
listenAddrs = append(listenAddrs, pa)
}
}
func setupTimeouts() {
var err error
readTimeout, err = time.ParseDuration(*readTimeoutStr)
if err != nil {
log.WithField("read_timeout", *readTimeoutStr).
WithError(err).
Fatal("read_timeout duration string invalid")
}
if readTimeout.Seconds() < 1 {
log.WithField("read_timeout", *readTimeoutStr).
Fatal("read_timeout less than one second")
}
writeTimeout, err = time.ParseDuration(*writeTimeoutStr)
if err != nil {
log.WithField("write_timeout", *writeTimeoutStr).
WithError(err).
Fatal("write_timeout duration string invalid")
}
if writeTimeout.Seconds() < 1 {
log.WithField("write_timeout", *writeTimeoutStr).
Fatal("write_timeout less than one second")
}
dataTimeout, err = time.ParseDuration(*dataTimeoutStr)
if err != nil {
log.WithField("data_timeout", *dataTimeoutStr).
WithError(err).
Fatal("data_timeout duration string invalid")
}
if dataTimeout.Seconds() < 1 {
log.WithField("data_timeout", *dataTimeoutStr).
Fatal("data_timeout less than one second")
}
}
func ConfigLoad() {
iniflags.Parse()
// Set up logging as soon as possible
setupLogger()
if (*remoteHost == "") {
log.Warn("remote_host not set; mail will not be forwarded!")
if *remotesStr == "" && *command == "" {
log.Warn("no remotes or command set; mail will not be forwarded!")
}
setupAllowedNetworks()
setupAllowedPatterns()
setupRemoteAuth()
setupRemotes()
setupListeners()
setupTimeouts()
}

16
go.mod
View File

@@ -1,11 +1,19 @@
module github.com/decke/smtprelay
require (
github.com/chrj/smtpd v0.3.0
github.com/google/uuid v1.2.0
github.com/chrj/smtpd v0.3.1
github.com/google/uuid v1.3.0
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.7.1
github.com/vharitonsky/iniflags v0.0.0-20180513140207-a33cd0b5f3de
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4
)
go 1.13
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
go 1.18

30
go.sum
View File

@@ -1,24 +1,26 @@
github.com/chrj/smtpd v0.3.0 h1:cw1LSHDOz7N3XbkcZSF/bue9dh7ATKk5ZksfBztV6b0=
github.com/chrj/smtpd v0.3.0/go.mod h1:1hmG9KbrE10JG1SmvG79Krh4F6713oUrw2+gRp1oSYk=
github.com/chrj/smtpd v0.3.1 h1:kogHFkbFdKaoH3bgZkqNC9uVtKYOFfM3uV3rroBdooE=
github.com/chrj/smtpd v0.3.1/go.mod h1:JtABvV/LzvLmEIzy0NyDnrfMGOMd8wy5frAokwf6J9Q=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/eaigner/dkim v0.0.0-20150301120808-6fe4a7ee9cfb/go.mod h1:FSCIHbrqk7D01Mj8y/jW+NS1uoCerr+ad+IckTHTFf4=
github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs=
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/vharitonsky/iniflags v0.0.0-20180513140207-a33cd0b5f3de h1:fkw+7JkxF3U1GzQoX9h69Wvtvxajo5Rbzy6+YMMzPIg=
github.com/vharitonsky/iniflags v0.0.0-20180513140207-a33cd0b5f3de/go.mod h1:irMhzlTz8+fVFj6CH2AN2i+WI5S6wWFtK3MBCIxIpyI=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 h1:kUhD7nTDoI3fVd9G4ORWrbV5NY0liEs/Jg2pv5f+bBA=
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 h1:xHms4gcpe1YE7A3yIllJXP16CMAGuqwO2lX1mTyyRRc=
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@@ -16,7 +16,7 @@ func setupLogger() {
log = logrus.New()
// Handle logfile
if (*logFile == "") {
if *logFile == "" {
log.SetOutput(os.Stderr)
} else {
writer, err := os.OpenFile(*logFile, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0600)

51
main.go
View File

@@ -1,11 +1,13 @@
package main
import (
"bytes"
"crypto/tls"
"fmt"
"net"
"net/textproto"
"os"
"os/exec"
"os/signal"
"strings"
"syscall"
@@ -159,40 +161,51 @@ func mailHandler(peer smtpd.Peer, env smtpd.Envelope) error {
"from": env.Sender,
"to": env.Recipients,
"peer": peerIP,
"host": *remoteHost,
"uuid": generateUUID(),
})
if (*remoteHost == "") {
logger.Warning("remote_host not set; discarding mail")
if *remotesStr == "" && *command == "" {
logger.Warning("no remote_host or command set; discarding mail")
return nil
}
logger.Info("delivering mail from peer using smarthost")
env.AddReceivedLine(peer)
var sender string
if *command != "" {
cmdLogger := logger.WithField("command", *command)
if *remoteSender == "" {
sender = env.Sender
} else {
sender = *remoteSender
var stdout bytes.Buffer
var stderr bytes.Buffer
cmd := exec.Command(*command)
cmd.Stdin = bytes.NewReader(env.Data)
cmd.Stdout = &stdout
cmd.Stderr = &stderr
err := cmd.Run()
if err != nil {
cmdLogger.WithError(err).Error(stderr.String())
return smtpd.Error{Code: 554, Message: "External command failed"}
}
cmdLogger.Info("pipe command successful: " + stdout.String())
}
for _, remote := range remotes {
logger = logger.WithField("host", remote.Addr)
logger.Info("delivering mail from peer using smarthost")
err := SendMail(
*remoteHost,
remoteAuth,
sender,
remote,
env.Sender,
env.Recipients,
env.Data,
)
if err != nil {
var smtpError smtpd.Error
switch err.(type) {
switch err := err.(type) {
case *textproto.Error:
err := err.(*textproto.Error)
smtpError = smtpd.Error{Code: err.Code, Message: err.Msg}
logger.WithFields(logrus.Fields{
@@ -210,6 +223,8 @@ func mailHandler(peer smtpd.Peer, env smtpd.Envelope) error {
}
logger.Debug("delivery successful")
}
return nil
}
@@ -294,6 +309,12 @@ func main() {
server := &smtpd.Server{
Hostname: *hostName,
WelcomeMessage: *welcomeMsg,
ReadTimeout: readTimeout,
WriteTimeout: writeTimeout,
DataTimeout: dataTimeout,
MaxConnections: *maxConnections,
MaxMessageSize: *maxMessageSize,
MaxRecipients: *maxRecipients,
ConnectionChecker: connectionChecker,
SenderChecker: senderChecker,
RecipientChecker: recipientChecker,

84
remotes.go Normal file
View File

@@ -0,0 +1,84 @@
package main
import (
"fmt"
"net/smtp"
"net/url"
)
type Remote struct {
SkipVerify bool
Auth smtp.Auth
Scheme string
Hostname string
Port string
Addr string
Sender string
}
// ParseRemote creates a remote from a given url in the following format:
//
// smtp://[user[:password]@][netloc][:port][/remote_sender][?param1=value1&...]
// smtps://[user[:password]@][netloc][:port][/remote_sender][?param1=value1&...]
// starttls://[user[:password]@][netloc][:port][/remote_sender][?param1=value1&...]
//
// Supported Params:
// - skipVerify: can be "true" or empty to prevent ssl verification of remote server's certificate.
// - auth: can be "login" to trigger "LOGIN" auth instead of "PLAIN" auth
//
func ParseRemote(remoteURL string) (*Remote, error) {
u, err := url.Parse(remoteURL)
if err != nil {
return nil, err
}
if u.Scheme != "smtp" && u.Scheme != "smtps" && u.Scheme != "starttls" {
return nil, fmt.Errorf("'%s' is not a supported relay scheme", u.Scheme)
}
hostname, port := u.Hostname(), u.Port()
if port == "" {
switch u.Scheme {
case "smtp":
port = "25"
case "smtps":
port = "465"
case "starttls":
port = "587"
}
}
q := u.Query()
r := &Remote{
Scheme: u.Scheme,
Hostname: hostname,
Port: port,
Addr: fmt.Sprintf("%s:%s", hostname, port),
}
if u.User != nil {
pass, _ := u.User.Password()
user := u.User.Username()
if hasAuth, authVal := q.Has("auth"), q.Get("auth"); hasAuth {
if authVal != "login" {
return nil, fmt.Errorf("Auth must be login or not present, received '%s'", authVal)
}
r.Auth = LoginAuth(user, pass)
} else {
r.Auth = smtp.PlainAuth("", user, pass, u.Hostname())
}
}
if hasVal, skipVerify := q.Has("skipVerify"), q.Get("skipVerify"); hasVal && skipVerify != "false" {
r.SkipVerify = true
}
if u.Path != "" {
r.Sender = u.Path[1:]
}
return r, nil
}

114
remotes_test.go Normal file
View File

@@ -0,0 +1,114 @@
package main
import (
"net/smtp"
"testing"
"github.com/stretchr/testify/assert"
)
func AssertRemoteUrlEquals(t *testing.T, expected *Remote, remotUrl string) {
actual, err := ParseRemote(remotUrl)
assert.Nil(t, err)
assert.NotNil(t, actual)
assert.Equal(t, expected.Scheme, actual.Scheme, "Scheme %s", remotUrl)
assert.Equal(t, expected.Addr, actual.Addr, "Addr %s", remotUrl)
assert.Equal(t, expected.Hostname, actual.Hostname, "Hostname %s", remotUrl)
assert.Equal(t, expected.Port, actual.Port, "Port %s", remotUrl)
assert.Equal(t, expected.Sender, actual.Sender, "Sender %s", remotUrl)
assert.Equal(t, expected.SkipVerify, actual.SkipVerify, "SkipVerify %s", remotUrl)
if expected.Auth != nil || actual.Auth != nil {
assert.NotNil(t, expected, "Auth %s", remotUrl)
assert.NotNil(t, actual, "Auth %s", remotUrl)
assert.IsType(t, expected.Auth, actual.Auth)
}
}
func TestValidRemoteUrls(t *testing.T) {
AssertRemoteUrlEquals(t, &Remote{
Scheme: "smtp",
SkipVerify: false,
Auth: nil,
Hostname: "email.com",
Port: "25",
Addr: "email.com:25",
Sender: "",
}, "smtp://email.com")
AssertRemoteUrlEquals(t, &Remote{
Scheme: "smtp",
SkipVerify: true,
Auth: nil,
Hostname: "email.com",
Port: "25",
Addr: "email.com:25",
Sender: "",
}, "smtp://email.com?skipVerify")
AssertRemoteUrlEquals(t, &Remote{
Scheme: "smtp",
SkipVerify: false,
Auth: smtp.PlainAuth("", "user", "pass", ""),
Hostname: "email.com",
Port: "25",
Addr: "email.com:25",
Sender: "",
}, "smtp://user:pass@email.com")
AssertRemoteUrlEquals(t, &Remote{
Scheme: "smtp",
SkipVerify: false,
Auth: LoginAuth("user", "pass"),
Hostname: "email.com",
Port: "25",
Addr: "email.com:25",
Sender: "",
}, "smtp://user:pass@email.com?auth=login")
AssertRemoteUrlEquals(t, &Remote{
Scheme: "smtp",
SkipVerify: false,
Auth: LoginAuth("user", "pass"),
Hostname: "email.com",
Port: "25",
Addr: "email.com:25",
Sender: "sender@website.com",
}, "smtp://user:pass@email.com/sender@website.com?auth=login")
AssertRemoteUrlEquals(t, &Remote{
Scheme: "smtps",
SkipVerify: false,
Auth: LoginAuth("user", "pass"),
Hostname: "email.com",
Port: "465",
Addr: "email.com:465",
Sender: "sender@website.com",
}, "smtps://user:pass@email.com/sender@website.com?auth=login")
AssertRemoteUrlEquals(t, &Remote{
Scheme: "smtps",
SkipVerify: true,
Auth: LoginAuth("user", "pass"),
Hostname: "email.com",
Port: "8425",
Addr: "email.com:8425",
Sender: "sender@website.com",
}, "smtps://user:pass@email.com:8425/sender@website.com?auth=login&skipVerify")
AssertRemoteUrlEquals(t, &Remote{
Scheme: "starttls",
SkipVerify: true,
Auth: LoginAuth("user", "pass"),
Hostname: "email.com",
Port: "8425",
Addr: "email.com:8425",
Sender: "sender@website.com",
}, "starttls://user:pass@email.com:8425/sender@website.com?auth=login&skipVerify")
}
func TestMissingScheme(t *testing.T) {
_, err := ParseRemote("http://user:pass@email.com:8425/sender@website.com")
assert.NotNil(t, err, "Err must be present")
assert.Equal(t, err.Error(), "'http' is not a supported relay scheme")
}

47
smtp.go
View File

@@ -4,9 +4,11 @@
// Package smtp implements the Simple Mail Transfer Protocol as defined in RFC 5321.
// It also implements the following extensions:
//
// 8BITMIME RFC 1652
// AUTH RFC 2554
// STARTTLS RFC 3207
//
// Additional extensions may be handled by clients.
//
// The smtp package is frozen and is not accepting new features.
@@ -106,7 +108,7 @@ func (c *Client) Hello(localName string) error {
}
// cmd is a convenience function that sends a command and returns the response
func (c *Client) cmd(expectCode int, format string, args ...interface{}) (int, string, error) {
func (c *Client) cmd(expectCode int, format string, args ...any) (int, string, error) {
id, err := c.Text.Cmd(format, args...)
if err != nil {
return 0, "", err
@@ -137,12 +139,8 @@ func (c *Client) ehlo() error {
if len(extList) > 1 {
extList = extList[1:]
for _, line := range extList {
args := strings.SplitN(line, " ", 2)
if len(args) > 1 {
ext[args[0]] = args[1]
} else {
ext[args[0]] = ""
}
k, v, _ := strings.Cut(line, " ")
ext[k] = v
}
}
if mechs, ok := ext["AUTH"]; ok {
@@ -322,7 +320,11 @@ var testHookStartTLS func(*tls.Config) // nil, except for tests
// attachments (see the mime/multipart package), or other mail
// functionality. Higher-level packages exist outside of the standard
// library.
func SendMail(addr string, a smtp.Auth, from string, to []string, msg []byte) error {
func SendMail(r *Remote, from string, to []string, msg []byte) error {
if r.Sender != "" {
from = r.Sender
}
if err := validateLine(from); err != nil {
return err
}
@@ -331,19 +333,19 @@ func SendMail(addr string, a smtp.Auth, from string, to []string, msg []byte) er
return err
}
}
host, port, err := net.SplitHostPort(addr)
if err != nil {
return err
}
var c *Client
if port == "465" || port == "smtps" {
config := &tls.Config{ServerName: host}
conn, err := tls.Dial("tcp", addr, config)
var err error
if r.Scheme == "smtps" {
config := &tls.Config{
ServerName: r.Hostname,
InsecureSkipVerify: r.SkipVerify,
}
conn, err := tls.Dial("tcp", r.Addr, config)
if err != nil {
return err
}
defer conn.Close()
c, err = NewClient(conn, host)
c, err = NewClient(conn, r.Hostname)
if err != nil {
return err
}
@@ -351,7 +353,7 @@ func SendMail(addr string, a smtp.Auth, from string, to []string, msg []byte) er
return err
}
} else {
c, err = Dial(addr)
c, err = Dial(r.Addr)
if err != nil {
return err
}
@@ -360,20 +362,25 @@ func SendMail(addr string, a smtp.Auth, from string, to []string, msg []byte) er
return err
}
if ok, _ := c.Extension("STARTTLS"); ok {
config := &tls.Config{ServerName: c.serverName}
config := &tls.Config{
ServerName: c.serverName,
InsecureSkipVerify: r.SkipVerify,
}
if testHookStartTLS != nil {
testHookStartTLS(config)
}
if err = c.StartTLS(config); err != nil {
return err
}
} else if r.Scheme == "starttls" {
return errors.New("starttls: server does not support extension, check remote scheme")
}
}
if a != nil && c.ext != nil {
if r.Auth != nil && c.ext != nil {
if _, ok := c.ext["AUTH"]; !ok {
return errors.New("smtp: server doesn't support AUTH")
}
if err = c.Auth(a); err != nil {
if err = c.Auth(r.Auth); err != nil {
return err
}
}

View File

@@ -30,6 +30,33 @@
; accepting mails from client.
;local_forcetls = false
; Socket timeout for read operations
; Duration string as sequence of decimal numbers,
; each with optional fraction and a unit suffix.
; Valid time units are "ns", "us", "ms", "s", "m", "h".
;read_timeout = 60s
; Socket timeout for write operations
; Duration string as sequence of decimal numbers,
; each with optional fraction and a unit suffix.
; Valid time units are "ns", "us", "ms", "s", "m", "h".
;write_timeout = 60s
; Socket timeout for DATA command
; Duration string as sequence of decimal numbers,
; each with optional fraction and a unit suffix.
; Valid time units are "ns", "us", "ms", "s", "m", "h".
;data_timeout = 5m
; Max concurrent connections, use -1 to disable
;max_connections = 100
; Max message size in bytes
;max_message_size = 10240000
; Max RCPT TO calls for each envelope
;max_recipients = 100
; Networks that are allowed to send mails to us
; Defaults to localhost. If set to "", then any address is allowed.
;allowed_nets = 127.0.0.0/8 ::1/128
@@ -56,25 +83,40 @@
; E.g. "app@example.com,@appsrv.example.com"
;allowed_users =
; Relay all mails to this SMTP server.
; Relay all mails to this SMTP servers.
; If not set, mails are discarded.
;
; Format:
; protocol://[user[:password]@][netloc][:port][/remote_sender][?param1=value1&...]
;
; protocol: smtp (unencrypted), smtps (TLS), starttls (STARTTLS)
; user: Username for authentication
; password: Password for authentication
; remote_sender: Email address to use as FROM
; params:
; skipVerify: "true" or empty to prevent ssl verification of remote server's certificate
; auth: "login" to use LOGIN authentication
; GMail
;remote_host = smtp.gmail.com:587
;remotes = starttls://user:pass@smtp.gmail.com:587
; Mailgun.org
;remote_host = smtp.mailgun.org:587
;remotes = starttls://user:pass@smtp.mailgun.org:587
; Mailjet.com
;remote_host = in-v3.mailjet.com:587
;remotes = starttls://user:pass@in-v3.mailjet.com:587
; Authentication credentials on outgoing SMTP server
;remote_user =
;remote_pass =
; Ignore remote host certificates
;remotes = starttls://user:pass@server:587?skipVerify
; Authentication method on outgoing SMTP server
; (none, plain, login)
;remote_auth = none
; Login Authentication method on outgoing SMTP server
;remotes = smtp://user:pass@server:2525?auth=login
; Sender e-mail address on outgoing SMTP server
;remote_sender =
;remotes = smtp://user:pass@server:2525/overridden@email.com?auth=login
; Multiple remotes, space delimited
;remotes = smtp://127.0.0.1:1025 starttls://user:pass@smtp.mailgun.org:587
; Pipe messages to external command
;command = /usr/local/bin/script