mirror of https://github.com/gophish/gophish
Phishing emails are now sent in "First Last <email@domain.com>" format.
parent
772fe28c06
commit
269568148e
|
@ -2,6 +2,7 @@ package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"net/mail"
|
"net/mail"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -50,6 +51,19 @@ type Target struct {
|
||||||
Position string `json:"position"`
|
Position string `json:"position"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns the email address to use in the "To" header of the email
|
||||||
|
func (t *Target) FormatAddress() string {
|
||||||
|
addr := t.Email
|
||||||
|
if t.FirstName != "" && t.LastName != "" {
|
||||||
|
a := &mail.Address{
|
||||||
|
Name: fmt.Sprintf("%s %s", t.FirstName, t.LastName),
|
||||||
|
Address: t.Email,
|
||||||
|
}
|
||||||
|
addr = a.String()
|
||||||
|
}
|
||||||
|
return addr
|
||||||
|
}
|
||||||
|
|
||||||
// ErrNoEmailSpecified is thrown when no email is specified for the Target
|
// ErrNoEmailSpecified is thrown when no email is specified for the Target
|
||||||
var ErrEmailNotSpecified = errors.New("No email address specified")
|
var ErrEmailNotSpecified = errors.New("No email address specified")
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/mail"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -348,3 +349,21 @@ func (s *ModelsSuite) TestGenerateResultId(c *check.C) {
|
||||||
c.Assert(err, check.Equals, nil)
|
c.Assert(err, check.Equals, nil)
|
||||||
c.Assert(match, check.Equals, true)
|
c.Assert(match, check.Equals, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *ModelsSuite) TestFormatAddress(c *check.C) {
|
||||||
|
r := Result{
|
||||||
|
FirstName: "John",
|
||||||
|
LastName: "Doe",
|
||||||
|
Email: "johndoe@example.com",
|
||||||
|
}
|
||||||
|
expected := &mail.Address{
|
||||||
|
Name: "John Doe",
|
||||||
|
Address: "johndoe@example.com",
|
||||||
|
}
|
||||||
|
c.Assert(r.FormatAddress(), check.Equals, expected.String())
|
||||||
|
|
||||||
|
r = Result{
|
||||||
|
Email: "johndoe@example.com",
|
||||||
|
}
|
||||||
|
c.Assert(r.FormatAddress(), check.Equals, r.Email)
|
||||||
|
}
|
||||||
|
|
|
@ -2,9 +2,11 @@ package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"math/big"
|
"math/big"
|
||||||
"net"
|
"net"
|
||||||
|
"net/mail"
|
||||||
|
|
||||||
"github.com/jinzhu/gorm"
|
"github.com/jinzhu/gorm"
|
||||||
"github.com/oschwald/maxminddb-golang"
|
"github.com/oschwald/maxminddb-golang"
|
||||||
|
@ -88,6 +90,19 @@ func (r *Result) GenerateId() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns the email address to use in the "To" header of the email
|
||||||
|
func (r *Result) FormatAddress() string {
|
||||||
|
addr := r.Email
|
||||||
|
if r.FirstName != "" && r.LastName != "" {
|
||||||
|
a := &mail.Address{
|
||||||
|
Name: fmt.Sprintf("%s %s", r.FirstName, r.LastName),
|
||||||
|
Address: r.Email,
|
||||||
|
}
|
||||||
|
addr = a.String()
|
||||||
|
}
|
||||||
|
return addr
|
||||||
|
}
|
||||||
|
|
||||||
// GetResult returns the Result object from the database
|
// GetResult returns the Result object from the database
|
||||||
// given the ResultId
|
// given the ResultId
|
||||||
func GetResult(rid string) (Result, error) {
|
func GetResult(rid string) (Result, error) {
|
||||||
|
|
|
@ -168,7 +168,7 @@ func processCampaign(c *models.Campaign) {
|
||||||
}
|
}
|
||||||
e.SetHeader("Subject", subjBuff.String())
|
e.SetHeader("Subject", subjBuff.String())
|
||||||
Logger.Println("Creating email using template")
|
Logger.Println("Creating email using template")
|
||||||
e.SetHeader("To", t.Email)
|
e.SetHeader("To", t.FormatAddress())
|
||||||
if c.Template.Text != "" {
|
if c.Template.Text != "" {
|
||||||
var textBuff bytes.Buffer
|
var textBuff bytes.Buffer
|
||||||
tmpl, err = template.New("text_template").Parse(c.Template.Text)
|
tmpl, err = template.New("text_template").Parse(c.Template.Text)
|
||||||
|
@ -302,7 +302,7 @@ func SendTestEmail(s *models.SendTestEmailRequest) error {
|
||||||
e.SetHeader(parsedHeader.Key.String(), parsedHeader.Value.String())
|
e.SetHeader(parsedHeader.Key.String(), parsedHeader.Value.String())
|
||||||
}
|
}
|
||||||
e.SetHeader("From", s.SMTP.FromAddress)
|
e.SetHeader("From", s.SMTP.FromAddress)
|
||||||
e.SetHeader("To", s.Email)
|
e.SetHeader("To", s.FormatAddress())
|
||||||
// Parse the templates
|
// Parse the templates
|
||||||
var subjBuff bytes.Buffer
|
var subjBuff bytes.Buffer
|
||||||
tmpl, err := template.New("text_template").Parse(s.Template.Subject)
|
tmpl, err := template.New("text_template").Parse(s.Template.Subject)
|
||||||
|
|
Loading…
Reference in New Issue