<commit_before>// Adapted from Google Appengine mail package.
package mail

import (
	"bytes"
	"log"
	"net/smtp"
	"text/template"

	"github.com/hackedu/backend/v1/helper"
)

var auth smtp.Auth

func init() {
	auth = smtp.PlainAuth(
		"",
		helper.GetConfig("SMTP_USERNAME"),
		helper.GetConfig("SMTP_PASSWORD"),
		helper.GetConfig("SMTP_HOST"),
	)
}

type Message struct {
	Sender  string
	To      []string
	Subject string
	Body    string
}

const emailTemplate = `From: {{.Sender}}
To: {{range .To}}{{.}},{{end}}
Subject: {{.Subject}}

{{.Body}}
`

// Send sends an email message.
func Send(msg *Message) error {
	var doc bytes.Buffer

	t := template.New("emailTemplate")
	t, err := t.Parse(emailTemplate)
	if err != nil {
		log.Println("Error parsing mail template", err)
		return err
	}
	err = t.Execute(&doc, msg)
	if err != nil {
		log.Println("Error executing mail template", err)
		return err
	}

	err = smtp.SendMail(
		helper.GetConfig("SMTP_HOST")+":"+helper.GetConfig("SMTP_PORT"),
		auth,
		msg.Sender,
		msg.To,
		doc.Bytes(),
	)

	if err != nil {
		return err
	}

	return nil
}<commit_msg>All error handling should be taken care of in the route handler's logic.<commit_after>// Adapted from Google Appengine mail package.
package mail

import (
	"bytes"
	"errors"
	"net/smtp"
	"text/template"

	"github.com/hackedu/backend/v1/helper"
)

var auth smtp.Auth

func init() {
	auth = smtp.PlainAuth(
		"",
		helper.GetConfig("SMTP_USERNAME"),
		helper.GetConfig("SMTP_PASSWORD"),
		helper.GetConfig("SMTP_HOST"),
	)
}

type Message struct {
	Sender  string
	To      []string
	Subject string
	Body    string
}

const emailTemplate = `From: {{.Sender}}
To: {{range .To}}{{.}},{{end}}
Subject: {{.Subject}}

{{.Body}}
`

// Send sends an email message.
func Send(msg *Message) error {
	var doc bytes.Buffer

	t := template.New("emailTemplate")
	t, err := t.Parse(emailTemplate)
	if err != nil {
		return errors.New("Error parsing mail template: " + err.Error())
	}
	err = t.Execute(&doc, msg)
	if err != nil {
		return errors.New("Error executing mail template: " + err.Error())
	}

	err = smtp.SendMail(
		helper.GetConfig("SMTP_HOST")+":"+helper.GetConfig("SMTP_PORT"),
		auth,
		msg.Sender,
		msg.To,
		doc.Bytes(),
	)
	if err != nil {
		return errors.New("Error sending email: " + err.Error())
	}

	return nil
}
{'fraction_non_alphanumeric': 0.16027574321413185, 'fraction_numerical': 0.0008616975441619991, 'mean_word_length': 3.7387755102040816, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '7452165', 'n_tokens_mistral': 891, 'n_tokens_neox': 843, 'n_words': 213}