<commit_before>package email

import (
	"path/filepath"

	"github.com/ewhal/nyaa/config"
	"github.com/ewhal/nyaa/util/log"
	gomail "gopkg.in/gomail.v2"
)

type EmailError error

var (
	mailer                 = InitGomail()
)

func InitGomail() *gomail.Dialer {
	mailer := gomail.NewDialer(config.EmailHost, config.EmailPort, config.EmailUsername, config.EmailPassword)
	return mailer
}

func SendEmailFromAdmin(to string, subject string, body string, bodyHTML string) error {
	msg := gomail.NewMessage()
	msg.SetHeader("From", config.EmailFrom)
	msg.SetHeader("To", to, config.EmailTestTo)
	msg.SetHeader("Subject", subject)
	msg.SetBody("text/plain", body)
	msg.AddAlternative("text/html", bodyHTML)
	log.Debugf("to : %s", to)
	log.Debugf("subject : %s", subject)
	log.Debugf("body : %s", body)
	log.Debugf("bodyHTML : %s", bodyHTML)
	if config.SendEmail {
		log.Debug("SendEmail performed.")

		err := mailer.DialAndSend(msg); 
		return err
	}
	return nil
}

func SendTestEmail() error {
	msg := gomail.NewMessage()
	msg.SetHeader("From", config.EmailFrom)
	msg.SetHeader("To", config.EmailTestTo)
	msg.SetAddressHeader("Cc", config.EmailTestTo, "NyaaPantsu")
	msg.SetHeader("Subject", "Hi(안녕하세요)?!")
	msg.SetBody("text/plain", "Hi(안녕하세요)?!")
	msg.AddAlternative("text/html", "<p><b>Nowplay(나우플레이)</b> means <i>Let's play</i>!!?</p>")
	path, err := filepath.Abs("img/megumin.png")
	if err != nil {
		panic(err)
	}
	msg.Attach(path)
	// SendEmail(msg)
		err := mailer.DialAndSend(msg); 
	return err
}<commit_msg>Update email.go<commit_after>package email

import (
	"path/filepath"

	"github.com/ewhal/nyaa/config"
	"github.com/ewhal/nyaa/util/log"
	gomail "gopkg.in/gomail.v2"
)

type EmailError error

var (
	mailer                 = InitGomail()
)

func InitGomail() *gomail.Dialer {
	mailer := gomail.NewDialer(config.EmailHost, config.EmailPort, config.EmailUsername, config.EmailPassword)
	return mailer
}

func SendEmailFromAdmin(to string, subject string, body string, bodyHTML string) error {
	msg := gomail.NewMessage()
	msg.SetHeader("From", config.EmailFrom)
	msg.SetHeader("To", to, config.EmailTestTo)
	msg.SetHeader("Subject", subject)
	msg.SetBody("text/plain", body)
	msg.AddAlternative("text/html", bodyHTML)
	log.Debugf("to : %s", to)
	log.Debugf("subject : %s", subject)
	log.Debugf("body : %s", body)
	log.Debugf("bodyHTML : %s", bodyHTML)
	if config.SendEmail {
		log.Debug("SendEmail performed.")

		err := mailer.DialAndSend(msg); 
		return err
	}
	return nil
}

func SendTestEmail() error {
	msg := gomail.NewMessage()
	msg.SetHeader("From", config.EmailFrom)
	msg.SetHeader("To", config.EmailTestTo)
	msg.SetAddressHeader("Cc", config.EmailTestTo, "NyaaPantsu")
	msg.SetHeader("Subject", "Hi(안녕하세요)?!")
	msg.SetBody("text/plain", "Hi(안녕하세요)?!")
	msg.AddAlternative("text/html", "<p><b>Nowplay(나우플레이)</b> means <i>Let's play</i>!!?</p>")
	path, err := filepath.Abs("img/megumin.png")
	if err != nil {
		panic(err)
	}
	msg.Attach(path)
	// SendEmail(msg)
	err := mailer.DialAndSend(msg)
	return err
}
{'fraction_non_alphanumeric': 0.171900826446281, 'fraction_numerical': 0.0006611570247933885, 'mean_word_length': 4.8757281553398055, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5961814', 'n_tokens_mistral': 1216, 'n_tokens_neox': 1210, 'n_words': 207}