readme updates

This commit is contained in:
wiggin77 2018-11-28 20:24:10 -05:00
parent 3fd8f73c8b
commit 6d3343b632
6 changed files with 100 additions and 17 deletions

21
LICENSE Normal file
View File

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

43
README.md Normal file
View File

@ -0,0 +1,43 @@
# mailrelay
`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.
## Use case
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.
Run `mailrelay` on a local PC and set your device (e.g. scanner) to send mail to that PC.
`mailrelay` is written in Go, and can be compiled for any Go supported platform including Linux, MacOS, Windows.
## Example (Linux)
On local PC (192.168.1.54) create file `/etc/mailrelay.json` with contents:
/etc/mailrelay.json
```json
{
"smtp_server": "smtp.fastmail.com",
"smtp_port": 465,
"smtp_username": "username@fastmail.com",
"smtp_password": "secretAppPassword",
"local_listen_ip": "0.0.0.0",
"local_listen_port": 2525
}
```
Run `mailrelay`,
```Bash
./mailrelay
```
Default location for configuration file is `/etc/mailrelay.json` but can be changed via `--config` flag. For example,
```bash
mailrelay --config=/home/myname/mailrelay.json
```
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.

View File

@ -17,8 +17,8 @@ type closeable interface {
}
// sendMail sends the contents of the envelope to a SMTP server.
func sendMail(e *mail.Envelope, config *mailRelayConfig) error {
server := fmt.Sprintf("%s:%d", config.Server, config.Port)
func sendMail(e *mail.Envelope, config *relayConfig) error {
server := fmt.Sprintf("%s:%d", config.SMTPServer, config.SMTPPort)
to := getTo(e)
var msg bytes.Buffer
@ -34,14 +34,14 @@ func sendMail(e *mail.Envelope, config *mailRelayConfig) error {
tlsconfig := &tls.Config{
InsecureSkipVerify: true,
ServerName: config.Server,
ServerName: config.SMTPServer,
}
if conn, err = tls.Dial("tcp", server, tlsconfig); err != nil {
return errors.Wrap(err, "dial error")
}
if client, err = smtp.NewClient(conn, config.Server); err != nil {
if client, err = smtp.NewClient(conn, config.SMTPServer); err != nil {
close(conn, "conn")
return errors.Wrap(err, "newclient error")
}
@ -52,7 +52,7 @@ func sendMail(e *mail.Envelope, config *mailRelayConfig) error {
}
}(&shouldCloseClient)
auth := smtp.PlainAuth("", config.Username, config.Password, config.Server)
auth := smtp.PlainAuth("", config.SMTPUsername, config.SMTPPassword, config.SMTPServer)
if err = client.Auth(auth); err != nil {
return errors.Wrap(err, "auth error")
}

8
mailrelay.json Normal file
View File

@ -0,0 +1,8 @@
{
"smtp_server": "smtp.fastmail.com",
"smtp_port": 465,
"smtp_username": "username@fastmail.com",
"smtp_password": "secret_app_password",
"local_listen_port": "0.0.0.0",
"local_listen_ip": 2525
}

10
main.go
View File

@ -15,10 +15,12 @@ type loggerLevels struct {
}
type mailRelayConfig struct {
Server string `json:"server"`
Port int `json:"port"`
Username string `json:"username"`
Password string `json:"password"`
SMTPServer string `json:"smtp_server"`
SMTPPort int `json:"smtp_port"`
SMTPUsername string `json:"smtp_username"`
SMTPPassword string `json:"smtp_password"`
LocalListenIP string `json:"local_listen_ip"`
LocalListenPort int `json:"local_listen_port"`
}
// Logger provides application logging.

View File

@ -12,9 +12,11 @@ import (
// Start starts the server.
func Start(appConfig *mailRelayConfig) (err error) {
listen := fmt.Sprintf("%s:%d", appConfig.LocalListenIP, appConfig.LocalListenPort)
cfg := &guerrilla.AppConfig{LogFile: log.OutputStdout.String(), AllowedHosts: []string{"warpmail.net"}}
sc := guerrilla.ServerConfig{
ListenInterface: "0.0.0.0:2525",
ListenInterface: listen,
IsEnabled: true,
}
cfg.Servers = append(cfg.Servers, sc)
@ -24,10 +26,10 @@ func Start(appConfig *mailRelayConfig) (err error) {
"save_process": "HeadersParser|Header|Hasher|Debugger|MailRelay",
"log_received_mails": true,
"primary_mail_host": "homeoffice.com",
"username": appConfig.Username,
"password": appConfig.Password,
"server": appConfig.Server,
"port": appConfig.Port,
"smtp_username": appConfig.SMTPUsername,
"smtp_password": appConfig.SMTPPassword,
"smtp_server": appConfig.SMTPServer,
"smtp_port": appConfig.SMTPPort,
}
cfg.BackendConfig = bcfg
@ -37,16 +39,23 @@ func Start(appConfig *mailRelayConfig) (err error) {
return d.Start()
}
type relayConfig struct {
SMTPServer string `json:"smtp_server"`
SMTPPort int `json:"smtp_port"`
SMTPUsername string `json:"smtp_username"`
SMTPPassword string `json:"smtp_password"`
}
// mailRelayProcessor decorator relays emails to another SMTP server.
var mailRelayProcessor = func() backends.Decorator {
config := &mailRelayConfig{}
config := &relayConfig{}
initFunc := backends.InitializeWith(func(backendConfig backends.BackendConfig) error {
configType := backends.BaseConfig(&mailRelayConfig{})
configType := backends.BaseConfig(&relayConfig{})
bcfg, err := backends.Svc.ExtractConfig(backendConfig, configType)
if err != nil {
return err
}
config = bcfg.(*mailRelayConfig)
config = bcfg.(*relayConfig)
return nil
})
backends.Svc.AddInitializer(initFunc)