skipped 4 lines 5 5 "errors" 6 6 "net/mail" 7 7 "os" 8 + "regexp" 8 9 "strconv" 9 10 "strings" 10 11 "time" skipped 46 lines 57 58 // specified in the SMTP configuration 58 59 var ErrFromAddressNotSpecified = errors.New("No From Address specified") 59 60 61 + // ErrInvalidFromAddress is thrown when the SMTP From field in the sending 62 + // profiles containes a value that is not an email address 63 + var ErrInvalidFromAddress = errors.New("Invalid SMTP From address because it is not an email address") 64 + 60 65 // ErrHostNotSpecified is thrown when there is no Host specified 61 66 // in the SMTP configuration 62 67 var ErrHostNotSpecified = errors.New("No SMTP Host specified") skipped 13 lines 76 81 return ErrFromAddressNotSpecified 77 82 case s.Host == "": 78 83 return ErrHostNotSpecified 84 + case !validateFromAddress(s.FromAddress): 85 + return ErrInvalidFromAddress 79 86 } 80 87 _, err := mail.ParseAddress(s.FromAddress) 81 88 if err != nil { skipped 11 lines 93 100 return ErrInvalidHost 94 101 } 95 102 return err 103 + } 104 + 105 + // validateFromAddress validates 106 + func validateFromAddress(email string) bool { 107 + r, _ := regexp.Compile("^([a-zA-Z0-9_\\-\\.]+)@([a-zA-Z0-9_\\-\\.]+)\\.([a-zA-Z]{2,5})$") 108 + return r.MatchString(email) 96 109 } 97 110 98 111 // GetDialer returns a dialer for the given SMTP profile skipped 148 lines