Skip to content

Commit 6d3343b

Browse files
committed
readme updates
1 parent 3fd8f73 commit 6d3343b

File tree

6 files changed

+100
-17
lines changed

6 files changed

+100
-17
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 wiggin77
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# mailrelay
2+
3+
`mailrelay` is a simple mail relay that can take unauthenticated SMTP emails (e.g. over port 25) and relay them to authenticated, TLS-enabled SMTP servers. Plus it's easy to configure.
4+
5+
## Use case
6+
7+
Some older appliances such as scanners, multi-function printers, RAID cards or NAS boxes with monitoring, can only send email without any authentication or encryption over port 25. `mailrelay` can send those emails to your Gmail, Fastmail or other provider.
8+
9+
Run `mailrelay` on a local PC and set your device (e.g. scanner) to send mail to that PC.
10+
11+
`mailrelay` is written in Go, and can be compiled for any Go supported platform including Linux, MacOS, Windows.
12+
13+
## Example (Linux)
14+
15+
On local PC (192.168.1.54) create file `/etc/mailrelay.json` with contents:
16+
17+
/etc/mailrelay.json
18+
19+
```json
20+
{
21+
"smtp_server": "smtp.fastmail.com",
22+
"smtp_port": 465,
23+
"smtp_username": "[email protected]",
24+
"smtp_password": "secretAppPassword",
25+
"local_listen_ip": "0.0.0.0",
26+
"local_listen_port": 2525
27+
}
28+
```
29+
30+
Run `mailrelay`,
31+
32+
```Bash
33+
./mailrelay
34+
```
35+
36+
Default location for configuration file is `/etc/mailrelay.json` but can be changed via `--config` flag. For example,
37+
38+
```bash
39+
mailrelay --config=/home/myname/mailrelay.json
40+
```
41+
42+
Configure your scanner or other device to send SMTP mail to server `192.168.1.54:2525`. Each email will be relayed to `smtp.fastmail.com` using the credentials above, including any file attachments.
43+

client.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ type closeable interface {
1717
}
1818

1919
// sendMail sends the contents of the envelope to a SMTP server.
20-
func sendMail(e *mail.Envelope, config *mailRelayConfig) error {
21-
server := fmt.Sprintf("%s:%d", config.Server, config.Port)
20+
func sendMail(e *mail.Envelope, config *relayConfig) error {
21+
server := fmt.Sprintf("%s:%d", config.SMTPServer, config.SMTPPort)
2222
to := getTo(e)
2323

2424
var msg bytes.Buffer
@@ -34,14 +34,14 @@ func sendMail(e *mail.Envelope, config *mailRelayConfig) error {
3434

3535
tlsconfig := &tls.Config{
3636
InsecureSkipVerify: true,
37-
ServerName: config.Server,
37+
ServerName: config.SMTPServer,
3838
}
3939

4040
if conn, err = tls.Dial("tcp", server, tlsconfig); err != nil {
4141
return errors.Wrap(err, "dial error")
4242
}
4343

44-
if client, err = smtp.NewClient(conn, config.Server); err != nil {
44+
if client, err = smtp.NewClient(conn, config.SMTPServer); err != nil {
4545
close(conn, "conn")
4646
return errors.Wrap(err, "newclient error")
4747
}
@@ -52,7 +52,7 @@ func sendMail(e *mail.Envelope, config *mailRelayConfig) error {
5252
}
5353
}(&shouldCloseClient)
5454

55-
auth := smtp.PlainAuth("", config.Username, config.Password, config.Server)
55+
auth := smtp.PlainAuth("", config.SMTPUsername, config.SMTPPassword, config.SMTPServer)
5656
if err = client.Auth(auth); err != nil {
5757
return errors.Wrap(err, "auth error")
5858
}

mailrelay.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"smtp_server": "smtp.fastmail.com",
3+
"smtp_port": 465,
4+
"smtp_username": "[email protected]",
5+
"smtp_password": "secret_app_password",
6+
"local_listen_port": "0.0.0.0",
7+
"local_listen_ip": 2525
8+
}

main.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ type loggerLevels struct {
1515
}
1616

1717
type mailRelayConfig struct {
18-
Server string `json:"server"`
19-
Port int `json:"port"`
20-
Username string `json:"username"`
21-
Password string `json:"password"`
18+
SMTPServer string `json:"smtp_server"`
19+
SMTPPort int `json:"smtp_port"`
20+
SMTPUsername string `json:"smtp_username"`
21+
SMTPPassword string `json:"smtp_password"`
22+
LocalListenIP string `json:"local_listen_ip"`
23+
LocalListenPort int `json:"local_listen_port"`
2224
}
2325

2426
// Logger provides application logging.

server.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ import (
1212
// Start starts the server.
1313
func Start(appConfig *mailRelayConfig) (err error) {
1414

15+
listen := fmt.Sprintf("%s:%d", appConfig.LocalListenIP, appConfig.LocalListenPort)
16+
1517
cfg := &guerrilla.AppConfig{LogFile: log.OutputStdout.String(), AllowedHosts: []string{"warpmail.net"}}
1618
sc := guerrilla.ServerConfig{
17-
ListenInterface: "0.0.0.0:2525",
19+
ListenInterface: listen,
1820
IsEnabled: true,
1921
}
2022
cfg.Servers = append(cfg.Servers, sc)
@@ -24,10 +26,10 @@ func Start(appConfig *mailRelayConfig) (err error) {
2426
"save_process": "HeadersParser|Header|Hasher|Debugger|MailRelay",
2527
"log_received_mails": true,
2628
"primary_mail_host": "homeoffice.com",
27-
"username": appConfig.Username,
28-
"password": appConfig.Password,
29-
"server": appConfig.Server,
30-
"port": appConfig.Port,
29+
"smtp_username": appConfig.SMTPUsername,
30+
"smtp_password": appConfig.SMTPPassword,
31+
"smtp_server": appConfig.SMTPServer,
32+
"smtp_port": appConfig.SMTPPort,
3133
}
3234
cfg.BackendConfig = bcfg
3335

@@ -37,16 +39,23 @@ func Start(appConfig *mailRelayConfig) (err error) {
3739
return d.Start()
3840
}
3941

42+
type relayConfig struct {
43+
SMTPServer string `json:"smtp_server"`
44+
SMTPPort int `json:"smtp_port"`
45+
SMTPUsername string `json:"smtp_username"`
46+
SMTPPassword string `json:"smtp_password"`
47+
}
48+
4049
// mailRelayProcessor decorator relays emails to another SMTP server.
4150
var mailRelayProcessor = func() backends.Decorator {
42-
config := &mailRelayConfig{}
51+
config := &relayConfig{}
4352
initFunc := backends.InitializeWith(func(backendConfig backends.BackendConfig) error {
44-
configType := backends.BaseConfig(&mailRelayConfig{})
53+
configType := backends.BaseConfig(&relayConfig{})
4554
bcfg, err := backends.Svc.ExtractConfig(backendConfig, configType)
4655
if err != nil {
4756
return err
4857
}
49-
config = bcfg.(*mailRelayConfig)
58+
config = bcfg.(*relayConfig)
5059
return nil
5160
})
5261
backends.Svc.AddInitializer(initFunc)

0 commit comments

Comments
 (0)