Пример #1
0
func convertConfig(config booking_mail_config.Config) (mailer.Config, error) {
	result := mailer_config.New()

	host, err := config.SmtpHost()
	if err != nil {
		return nil, err
	}
	result.SetSmtpHost(host)

	password, err := config.SmtpPassword()
	if err != nil {
		return nil, err
	}
	result.SetSmtpPassword(password)

	port, err := config.SmtpPort()
	if err != nil {
		return nil, err
	}
	result.SetSmtpPort(port)

	user, err := config.SmtpUser()
	if err != nil {
		return nil, err
	}
	result.SetSmtpUser(user)

	return result, nil
}
Пример #2
0
func (m *mailService) SendMail(mail *booking_mail.Mail, config booking_mail_config.Config) error {
	if len(mail.Sender) == 0 {
		sender, err := config.SmtpDefaultSender()
		if err != nil {
			return err
		}
		mail.Sender = sender
	}
	if err := validateMail(mail); err != nil {
		return err
	}
	message := convertMailToMessage(mail)
	mailerConfig, err := convertConfig(config)
	if err != nil {
		return err
	}
	return mailer.New(mailerConfig).Send(message)
}