@@ -144,16 +144,15 @@ func newMailService() {
144
144
}
145
145
}
146
146
147
+ // we want to warn if users use SMTP on a non-local IP;
148
+ // we might as well take the opportunity to check that it has an IP at all
149
+ ips := tryResolveAddr (MailService .SMTPAddr )
147
150
if MailService .Protocol == "smtp" {
148
- switch MailService .SMTPAddr {
149
- case "localhost" :
150
- case "127.0.0.1" :
151
- case "::1" :
152
- case "[::1]" :
153
- // this is a local address, so, we're fine
154
- break
155
- default :
156
- log .Warn ("connect via insecure SMTP to non-local address" )
151
+ for _ , ip := range ips {
152
+ if ! ip .IsLoopback () {
153
+ log .Warn ("connect via insecure SMTP to non-local address" )
154
+ break
155
+ }
157
156
}
158
157
}
159
158
@@ -246,3 +245,21 @@ func newNotifyMailService() {
246
245
Service .EnableNotifyMail = true
247
246
log .Info ("Notify Mail Service Enabled" )
248
247
}
248
+
249
+ func tryResolveAddr (addr string ) []net.IP {
250
+ if strings .HasPrefix (addr , "[" ) && strings .HasSuffix (addr , "]" ) {
251
+ addr = addr [1 : len (addr )- 1 ]
252
+ }
253
+ ip := net .ParseIP (addr )
254
+ if ip != nil {
255
+ ips := make ([]net.IP , 1 )
256
+ ips [0 ] = ip
257
+ return ips
258
+ }
259
+ ips , err := net .LookupIP (addr )
260
+ if err != nil {
261
+ log .Warn ("could not look up mailer.SMTP_ADDR: %v" , err )
262
+ return make ([]net.IP , 0 )
263
+ }
264
+ return ips
265
+ }
0 commit comments