2014-06-03 18:27:20 +00:00
|
|
|
package models
|
|
|
|
|
2016-02-02 00:36:59 +00:00
|
|
|
import "errors"
|
|
|
|
|
2015-02-07 20:31:41 +00:00
|
|
|
// SMTP contains the attributes needed to handle the sending of campaign emails
|
2014-06-03 18:27:20 +00:00
|
|
|
type SMTP struct {
|
2015-02-07 20:31:41 +00:00
|
|
|
SMTPId int64 `json:"-" gorm:"column:smtp_id; primary_key:yes"`
|
|
|
|
CampaignId int64 `json:"-" gorm:"column:campaign_id"`
|
2014-06-05 04:54:46 +00:00
|
|
|
Host string `json:"host"`
|
2014-06-03 18:27:20 +00:00
|
|
|
Username string `json:"username,omitempty"`
|
|
|
|
Password string `json:"password,omitempty" sql:"-"`
|
|
|
|
FromAddress string `json:"from_address"`
|
|
|
|
}
|
|
|
|
|
2016-02-02 00:36:59 +00:00
|
|
|
// ErrFromAddressNotSpecified is thrown when there is no "From" address
|
|
|
|
// specified in the SMTP configuration
|
|
|
|
var ErrFromAddressNotSpecified = errors.New("No From Address specified")
|
|
|
|
|
|
|
|
// ErrHostNotSpecified is thrown when there is no Host specified
|
|
|
|
// in the SMTP configuration
|
|
|
|
var ErrHostNotSpecified = errors.New("No SMTP Host specified")
|
|
|
|
|
2015-02-07 20:31:41 +00:00
|
|
|
// TableName specifies the database tablename for Gorm to use
|
|
|
|
func (s SMTP) TableName() string {
|
|
|
|
return "smtp"
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate ensures that SMTP configs/connections are valid
|
2016-02-02 00:36:59 +00:00
|
|
|
func (s *SMTP) Validate() error {
|
2014-06-03 18:27:20 +00:00
|
|
|
switch {
|
|
|
|
case s.FromAddress == "":
|
2016-02-02 00:36:59 +00:00
|
|
|
return ErrFromAddressNotSpecified
|
2014-06-05 04:54:46 +00:00
|
|
|
case s.Host == "":
|
2016-02-02 00:36:59 +00:00
|
|
|
return ErrHostNotSpecified
|
2014-06-03 18:27:20 +00:00
|
|
|
}
|
2016-02-02 00:36:59 +00:00
|
|
|
return nil
|
2014-06-03 18:27:20 +00:00
|
|
|
}
|