You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: email.go
    path of file: ./repos/studygolang/internal/logic
    
    the code of the file until where you have to start completion: // Copyright 2016 The StudyGolang Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// http://studygolang.com
// Author:polaris	polaris@studygolang.com

package logic

import (
	"bytes"
	"crypto/tls"
	"fmt"
	"html/template"
	"net/smtp"
	"strings"
	"time"

	. "github.com/studygolang/studygolang/db"
	"github.com/studygolang/studygolang/global"
	"github.com/studygolang/studygolang/internal/model"
	"github.com/studygolang/studygolang/util"

	"github.com/polaris1119/config"
	"github.com/polaris1119/email"
	"github.com/polaris1119/goutils"
	"github.com/polaris1119/logger"
)

type EmailLogic struct{}

var DefaultEmail = EmailLogic{}

// SendMail 发送普通（通知）电子邮件
func (e EmailLogic) SendMail(subject, content string, tos []string) (err error) {
	return e.sendMail(subject, content, tos, "email")
}

// SendAuthMail 发送验证电子邮件
func (e EmailLogic) SendAuthMail(subject, content string, tos []string) error {
	return e.sendMail(subject, content, tos, "email.auth")
}

// sendMail 发送电子邮件
func (EmailLogic) sendMail(subject, content string, tos []string, section string) (err error) {
	emailConfig, _ := config.ConfigFile.GetSection(section)

	fromEmail := emailConfig["from_email"]
	smtpUsername := emailConfig["smtp_username"]
	smtpPassword := emailConfig["smtp_password"]
	smtpHost := emailConfig["smtp_host"]
	smtpPort := emailConfig["smtp_port"]

	mail := email.NewEmail()
	mail.From = WebsiteSetting.Name + ` <` + fromEmail + `>`
	mail.To = tos
	mail.Subject = subject
	mail.HTML = []byte(content)

	auth := smtp.PlainAuth("", smtpUsername, smtpPassword, smtpHost)
	smtpAddr := smtpHost + ":" + smtpPort

	if goutils.MustBool(emailConfig["tls"]) {
		tlsConfig := &tls.Config{
			In
    
func (self EmailLogic) EmailNotice() {

	beginDate := time.Now().Add(-7 * 24 * time.Hour).Format("2006-01-02")
	endDate := time.Now().Add(-24 * time.Hour).Format("2006-01-02")

	beginTime := beginDate + " 00:00:00"

	// 本周晨读（过去 7 天）
	readings, err := DefaultReading.FindLastList(beginTime)
	if err != nil {
		logger.Errorln("find morning reading error:", err)
	}

	// 本周精彩文章
	articles, err := DefaultArticle.FindLastList(beginTime, 10)
	if err != nil {
		logger.Errorln("find article error:", err)
	}

	// 本周热门主题
	topics, err := DefaultTopic.FindLastList(beginTime, 10)
	if err != nil {
		logger.Errorln("find topic error:", err)
	}

	global.App.SetCopyright()

	data := map[string]interface{}{
		"readings":  readings,
		"articles":  articles,
		"topics":    topics,
		"beginDate": beginDate,
		"endDate":   endDate,
		"setting":   WebsiteSetting,
		"app":       global.App,
	}

	// 给所有用户发送邮件
	var (
		lastUid = 0
		limit   = 500
		users   = make([]*model.User, 0)
	)

	day := time.Now().Day()
	monthDayNum := util.MonthDayNum(time.Now())

	for {
		err = MasterDB.Where("uid>?", lastUid).Asc("uid").Limit(limit).Find(&users)
		if err != nil {
			logger.Errorln("find user error:", err)
			continue
		}

		if len(users) == 0 {
			break
		}

		for _, user := range users {
			if lastUid < user.Uid {
				lastUid = user.Uid
			}

			if user.Uid%monthDayNum != day {
				continue
			}

			if user.Unsubscribe == 1 {
				logger.Infoln("user unsubscribe", user)
				continue
			}

			if user.Status != model.UserStatusAudit {
				logger.Infoln("user is not normal:", user)
				continue
			}

			if user.IsThird == 1 && strings.HasSuffix(user.Email, "github.com") {
				logger.Infoln("the email is not exists:", user)
				continue
			}

			data["email"] = user.Email
			data["token"] = self.GenUnsubscribeToken(user)

			content, err := self.genEmailContent(data)
			if err != nil {
				logger.Errorln("from email.html gen email content error:", err)
				continue
			}

			self.SendMail("每周精选", content, []string{user.Email})

			// 控制发信速度
			time.Sleep(60 * time.Second)
		}

		users = make([]*model.User, 0)
	}

}