2 // Copyright 2020 Blue Static <https://www.bluestatic.org>
3 // This program is free software licensed under the GNU General Public License,
4 // version 3.0. The full text of the license can be found in LICENSE.txt.
5 // SPDX-License-Identifier: GPL-3.0-only
13 "github.com/uber-go/zap"
16 func RelayMessage(env Envelope, log zap.Logger) {
17 for _, rcptTo := range env.RcptTo {
18 domain := DomainForAddress(rcptTo)
19 mx, err := net.LookupMX(domain)
20 if err != nil || len(mx) < 1 {
21 log.Error("failed to lookup MX records",
22 zap.String("address", rcptTo.Address),
24 deliverRelayFailure(env, err)
28 to := []string{rcptTo.Address}
29 from := env.MailFrom.Address
30 host := mx[0].Host + ":25"
32 log.Info("relay message",
33 zap.String("to", to[0]),
34 zap.String("from", from),
35 zap.String("server", host))
36 err = smtp.SendMail(host, nil, from, to, env.Data)
38 log.Error("failed to relay message",
39 zap.String("address", rcptTo.Address),
41 deliverRelayFailure(env, err)
47 func deliverRelayFailure(env Envelope, err error) {
48 // TODO: constructo a delivery status notification