Exemple #1
0
func (c *BaseController) SendMails(html string) {
	var users []M.User

	err := DM.FindAll(&M.User{}, &users, M.Sf{}, M.Where{And: M.W{"NotifyByMail": true}})

	if err != nil {
		beego.Error("Find users error ", err)
	}

	mail := M.Mail{}
	mail.ToType = "to"

	//Getting config data
	mail.FromMail = beego.AppConfig.String("mail::from_mail")
	mail.FromName = sql.NullString{beego.AppConfig.String("mail::from_name"), true}
	mail.Subject = sql.NullString{beego.AppConfig.String("mail::from_subject"), true}

	mail.Html = sql.NullString{html, true}
	mail.Text = sql.NullString{"", true}

	for _, user := range users {
		mail.ToName = sql.NullString{user.Name, true}
		mail.ToMail = user.Email
		//Send with Notification Service
		NFS.Send(mail)
	}
}
Exemple #2
0
func (s *MailStore) Insert(m *M.Mail) error {
	m.Created = time.Now()
	m.Active = true
	m.Status = true

	if _, err := s.db.Insert(m); err != nil {
		return err
	}

	return nil
}
Exemple #3
0
func newMail(id int) M.Mail {
	mail := M.Mail{}
	mail.Id = id
	mail.ToMail = "*****@*****.**"
	mail.ToName = sql.NullString{"Abdullo", true}
	mail.ToType = "to"
	mail.FromMail = "*****@*****.**"
	mail.FromName = sql.NullString{"hrkb", true}
	mail.Subject = sql.NullString{"notification", true}
	mail.Html = sql.NullString{"<h1>long interestin html</h1>", true}
	mail.Text = sql.NullString{"some text", true}
	return mail
}
Exemple #4
0
func (s *MailStore) Update(m *M.Mail) error {
	m.Updated = time.Now()

	if _, err := s.db.Update(m); err != nil {
		return err
	}
	return nil
}
Exemple #5
0
//Calls SendMail function and respondes to errors if they appear
func (n *NotifyMail) send(errChan ErrorChannel, mail M.Mail) {

	err := n.SendMail(mail)

	if err != nil {
		//If no internet connection sleep untill waitTime
		if strings.Contains(fmt.Sprintf("%s", err), "no such host") {
			time.Sleep(time.Duration(n.waitTime) * time.Second)
			errChan.In() <- errors.New("No internet connection mail")
		}

		//Try to resend mail n times
		if mail.Try >= n.retry {
			n.notifChan.In() <- fmt.Sprintf("Message sending failed after %d times %d", n.retry, mail.Id)
			mail.Status = false

			if err := n.store.Update(&mail); err != nil {
				n.errChan.In() <- err
			}

			return
		}

		//send to send mail channel again
		n.sendChan <- mail
		errChan.In() <- errors.New(fmt.Sprint("Resend: ", mail.Id))
		return
	}

	mail.Status = true
	if err := n.store.Update(&mail); err != nil {
		n.errChan.In() <- err
	}

	//If no errors send success notification
	n.notifChan.In() <- fmt.Sprintf("Mail ID: %d Succesfully sended at: %s", mail.Id)
}