mirror of https://github.com/gophish/gophish
Attachments are now fetched on GetTemplateByName
Attachments are now attached to emails (whoops!)pull/147/head
parent
0a7bfcf664
commit
1e3a02673c
|
@ -83,6 +83,14 @@ func GetTemplateByName(n string, uid int64) (Template, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Logger.Println(err)
|
Logger.Println(err)
|
||||||
}
|
}
|
||||||
|
err = db.Where("template_id=?", t.Id).Find(&t.Attachments).Error
|
||||||
|
if err != nil && err != gorm.RecordNotFound {
|
||||||
|
Logger.Println(err)
|
||||||
|
return t, err
|
||||||
|
}
|
||||||
|
if err == nil && len(t.Attachments) == 0 {
|
||||||
|
t.Attachments = make([]Attachment, 0)
|
||||||
|
}
|
||||||
return t, err
|
return t, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package worker
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"log"
|
"log"
|
||||||
|
@ -113,6 +114,14 @@ func processCampaign(c *models.Campaign) {
|
||||||
e.Subject = string(subjBuff.Bytes())
|
e.Subject = string(subjBuff.Bytes())
|
||||||
Logger.Println("Creating email using template")
|
Logger.Println("Creating email using template")
|
||||||
e.To = []string{t.Email}
|
e.To = []string{t.Email}
|
||||||
|
// Attach the files
|
||||||
|
for _, a := range c.Template.Attachments {
|
||||||
|
decoder := base64.NewDecoder(base64.StdEncoding, strings.NewReader(a.Content))
|
||||||
|
_, err = e.Attach(decoder, a.Name, a.Type)
|
||||||
|
if err != nil {
|
||||||
|
Logger.Println(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
Logger.Printf("Sending Email to %s\n", t.Email)
|
Logger.Printf("Sending Email to %s\n", t.Email)
|
||||||
err = e.SendWithTLS(c.SMTP.Host, auth, tc)
|
err = e.SendWithTLS(c.SMTP.Host, auth, tc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -206,6 +215,15 @@ func SendTestEmail(s *models.SendTestEmailRequest) error {
|
||||||
}
|
}
|
||||||
e.Subject = string(subjBuff.Bytes())
|
e.Subject = string(subjBuff.Bytes())
|
||||||
e.To = []string{s.Email}
|
e.To = []string{s.Email}
|
||||||
|
// Attach the files
|
||||||
|
for _, a := range s.Template.Attachments {
|
||||||
|
Logger.Printf("Attaching %s\n", a.Name)
|
||||||
|
decoder := base64.NewDecoder(base64.StdEncoding, strings.NewReader(a.Content))
|
||||||
|
_, err = e.Attach(decoder, a.Name, a.Type)
|
||||||
|
if err != nil {
|
||||||
|
Logger.Println(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
Logger.Printf("Sending Email to %s\n", s.Email)
|
Logger.Printf("Sending Email to %s\n", s.Email)
|
||||||
err = e.SendWithTLS(s.SMTP.Host, auth, t)
|
err = e.SendWithTLS(s.SMTP.Host, auth, t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue