mirror of https://github.com/gophish/gophish
Cleaning up some email sending bugs. Fixes #329
parent
0d8a793550
commit
b403e97eee
|
@ -140,6 +140,11 @@ func (c *Campaign) getDetails() error {
|
|||
c.Template = Template{Name: "[Deleted]"}
|
||||
Logger.Printf("%s: template not found for campaign\n", err)
|
||||
}
|
||||
err = db.Where("template_id=?", c.Template.Id).Find(&c.Template.Attachments).Error
|
||||
if err != nil && err != gorm.ErrRecordNotFound {
|
||||
Logger.Println(err)
|
||||
return err
|
||||
}
|
||||
err = db.Table("pages").Where("id=?", c.PageId).Find(&c.Page).Error
|
||||
if err != nil {
|
||||
if err != gorm.ErrRecordNotFound {
|
||||
|
|
|
@ -129,8 +129,6 @@ func processCampaign(c *models.Campaign) {
|
|||
}
|
||||
// Parse the templates
|
||||
var subjBuff bytes.Buffer
|
||||
var htmlBuff bytes.Buffer
|
||||
var textBuff bytes.Buffer
|
||||
tmpl, err := template.New("text_template").Parse(c.Template.Subject)
|
||||
if err != nil {
|
||||
Logger.Println(err)
|
||||
|
@ -142,6 +140,8 @@ func processCampaign(c *models.Campaign) {
|
|||
e.SetHeader("Subject", subjBuff.String())
|
||||
Logger.Println("Creating email using template")
|
||||
e.SetHeader("To", t.Email)
|
||||
if c.Template.Text != "" {
|
||||
var textBuff bytes.Buffer
|
||||
tmpl, err = template.New("text_template").Parse(c.Template.Text)
|
||||
if err != nil {
|
||||
Logger.Println(err)
|
||||
|
@ -151,6 +151,9 @@ func processCampaign(c *models.Campaign) {
|
|||
Logger.Println(err)
|
||||
}
|
||||
e.SetBody("text/plain", textBuff.String())
|
||||
}
|
||||
if c.Template.HTML != "" {
|
||||
var htmlBuff bytes.Buffer
|
||||
tmpl, err = template.New("html_template").Parse(c.Template.HTML)
|
||||
if err != nil {
|
||||
Logger.Println(err)
|
||||
|
@ -159,7 +162,12 @@ func processCampaign(c *models.Campaign) {
|
|||
if err != nil {
|
||||
Logger.Println(err)
|
||||
}
|
||||
if c.Template.Text == "" {
|
||||
e.SetBody("text/html", htmlBuff.String())
|
||||
} else {
|
||||
e.AddAlternative("text/html", htmlBuff.String())
|
||||
}
|
||||
}
|
||||
// Attach the files
|
||||
for _, a := range c.Template.Attachments {
|
||||
e.Attach(func(a models.Attachment) (string, gomail.FileSetting) {
|
||||
|
|
Loading…
Reference in New Issue