// @todo rework
// SendEmail sends email using system configured variables
@todo rework
SendEmail sends email using system configured variables
// @todo rework // SendEmail sends email using system configured variables
func SendEmail(from string, to []string, cc []string, bcc []string, subject string, body string) error {
	if !core.CurrentConfig.InTests && (core.CurrentConfig.D.Uadmin.EmailUsername == "" || core.CurrentConfig.D.Uadmin.EmailPassword == "" || core.CurrentConfig.D.Uadmin.EmailSMTPServer == "" || core.CurrentConfig.D.Uadmin.EmailSMTPServerPort == 0) {
		errMsg := "Email not sent because email global variables are not set"
		core.Trail(core.CRITICAL, errMsg)
		return fmt.Errorf(errMsg)
	}
	domain := strings.Split(from, "@")
	if !core.CurrentConfig.InTests && len(domain) < 2 {
		return nil
	}
	domain[0] = strings.TrimSpace(domain[0])
	domain[0] = strings.TrimSuffix(domain[0], ">")
	MIME := "MIME-version: 1.0;\nContent-Type: text/html; charset=\"UTF-8\";\n\n"
	msg := "From: " + from + "\r\n"
	msg += "To: " + strings.Join(to, ",") + "\r\n"
	if len(cc) > 0 {
		msg += "CC: " + strings.Join(cc, ",") + "\r\n"
	}
	msg += "Date: " + time.Now().UTC().Format(time.RFC1123Z) + "\r\n"
	msg += "Message-ID: " + fmt.Sprintf("<%s-%s-%s-%s-%s@%s>", GenerateBase32(8), GenerateBase32(4), GenerateBase32(4), GenerateBase32(4), GenerateBase32(12), domain[0]) + "\r\n"
	msg += "Subject: " + subject + "\r\n"
	msg += MIME + "\r\n"
	msg += strings.Replace(body, "\n", "<br/>", -1)
	msg += "\r\n"
	to = append(to, cc...)
	to = append(to, bcc...)
	if !core.CurrentConfig.InTests {
		go func() {
			err := smtp.SendMail(fmt.Sprintf("%s:%d", core.CurrentConfig.D.Uadmin.EmailSMTPServer, core.CurrentConfig.D.Uadmin.EmailSMTPServerPort),
				smtp.PlainAuth("", core.CurrentConfig.D.Uadmin.EmailUsername, core.CurrentConfig.D.Uadmin.EmailPassword, core.CurrentConfig.D.Uadmin.EmailSMTPServer),
				core.CurrentConfig.D.Uadmin.EmailFrom, to, []byte(msg))
			if err != nil {
				core.Trail(core.CRITICAL, "Email was not sent. %s", err)
			}
		}()
	} else {
		SentEmailsDuringTests.AddSentEmail(from, to, subject, cc, []byte(body))
	}
	return nil
}
func SendEmail ( from string , to [ ] string , cc [ ] string , bcc [ ] string , subject string , body string ) error { if ! core . CurrentConfig . InTests && ( core . CurrentConfig . D . Uadmin . EmailUsername == " " || core . CurrentConfig . D . Uadmin . EmailPassword == " " || core . CurrentConfig . D . Uadmin . EmailSMTPServer == " " || core . CurrentConfig . D . Uadmin . EmailSMTPServerPort == 0 ) { errMsg := " " core . Trail ( core . CRITICAL , errMsg ) return fmt . Errorf ( errMsg ) } domain := strings . Split ( from , " " ) if ! core . CurrentConfig . InTests && len ( domain ) < 2 { return nil } domain [ 0 ] = strings . TrimSpace ( domain [ 0 ] ) domain [ 0 ] = strings . TrimSuffix ( domain [ 0 ] , " " ) MIME := " \n \" \" \n \n " msg := " " + from + " \r \n " msg += " " + strings . Join ( to , " " ) + " \r \n " if len ( cc ) > 0 { msg += " " + strings . Join ( cc , " " ) + " \r \n " } msg += " " + time . Now ( ) . UTC ( ) . Format ( time . RFC1123Z ) + " \r \n " msg += " " + fmt . Sprintf ( " " , GenerateBase32 ( 8 ) , GenerateBase32 ( 4 ) , GenerateBase32 ( 4 ) , GenerateBase32 ( 4 ) , GenerateBase32 ( 12 ) , domain [ 0 ] ) + " \r \n " msg += " " + subject + " \r \n " msg += MIME + " \r \n " msg += strings . Replace ( body , " \n " , " " , - 1 ) msg += " \r \n " to = append ( to , cc ... ) to = append ( to , bcc ... ) if ! core . CurrentConfig . InTests { go func ( ) { err := smtp . SendMail ( fmt . Sprintf ( " " , core . CurrentConfig . D . Uadmin . EmailSMTPServer , core . CurrentConfig . D . Uadmin . EmailSMTPServerPort ) , smtp . PlainAuth ( " " , core . CurrentConfig . D . Uadmin . EmailUsername , core . CurrentConfig . D . Uadmin . EmailPassword , core . CurrentConfig . D . Uadmin . EmailSMTPServer ) , core . CurrentConfig . D . Uadmin . EmailFrom , to , [ ] byte ( msg ) ) if err != nil { core . Trail ( core . CRITICAL , " " , err ) } } ( ) } else { SentEmailsDuringTests . AddSentEmail ( from , to , subject , cc , [ ] byte ( body ) ) } return nil }
@todo rework
SendEmail sends email using system configured variables
@todo rework SendEmail sends email using system configured variables
// Get the domain name of sender // Construct the email // Append CC and BCC