parent
2ef05a20d5
commit
b61c2a7e3a
|
|
@ -118,6 +118,7 @@ type Config struct {
|
||||||
Port string
|
Port string
|
||||||
Username string
|
Username string
|
||||||
Password string
|
Password string
|
||||||
|
From string
|
||||||
|
|
||||||
CertLimit int
|
CertLimit int
|
||||||
NagTimes []string
|
NagTimes []string
|
||||||
|
|
|
||||||
|
|
@ -247,7 +247,7 @@ func main() {
|
||||||
tmpl, err := template.New("expiry-email").Parse(string(emailTmpl))
|
tmpl, err := template.New("expiry-email").Parse(string(emailTmpl))
|
||||||
cmd.FailOnError(err, "Could not parse email template")
|
cmd.FailOnError(err, "Could not parse email template")
|
||||||
|
|
||||||
mailClient := mail.New(c.Mailer.Server, c.Mailer.Port, c.Mailer.Username, c.Mailer.Password)
|
mailClient := mail.New(c.Mailer.Server, c.Mailer.Port, c.Mailer.Username, c.Mailer.Password, c.Mailer.From)
|
||||||
|
|
||||||
nagCheckInterval := defaultNagCheckInterval
|
nagCheckInterval := defaultNagCheckInterval
|
||||||
if s := c.Mailer.NagCheckInterval; s != "" {
|
if s := c.Mailer.NagCheckInterval; s != "" {
|
||||||
|
|
|
||||||
|
|
@ -64,13 +64,13 @@ func isASCII(str string) bool {
|
||||||
|
|
||||||
// New constructs a Mailer to represent an account on a particular mail
|
// New constructs a Mailer to represent an account on a particular mail
|
||||||
// transfer agent.
|
// transfer agent.
|
||||||
func New(server, port, username, password string) MailerImpl {
|
func New(server, port, username, password, from string) MailerImpl {
|
||||||
auth := smtp.PlainAuth("", username, password, server)
|
auth := smtp.PlainAuth("", username, password, server)
|
||||||
return MailerImpl{
|
return MailerImpl{
|
||||||
Server: server,
|
Server: server,
|
||||||
Port: port,
|
Port: port,
|
||||||
Auth: auth,
|
Auth: auth,
|
||||||
From: username,
|
From: from,
|
||||||
clk: clock.Default(),
|
clk: clock.Default(),
|
||||||
csprgSource: realSource{},
|
csprgSource: realSource{},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,9 @@ func (f fakeSource) generate() *big.Int {
|
||||||
|
|
||||||
func TestGenerateMessage(t *testing.T) {
|
func TestGenerateMessage(t *testing.T) {
|
||||||
fc := clock.NewFake()
|
fc := clock.NewFake()
|
||||||
m := MailerImpl{From: "send@email.com", clk: fc, csprgSource: fakeSource{}}
|
m := New("", "", "", "", "send@email.com")
|
||||||
|
m.clk = fc
|
||||||
|
m.csprgSource = fakeSource{}
|
||||||
messageBytes, err := m.generateMessage([]string{"recv@email.com"}, "test subject", "this is the body\n")
|
messageBytes, err := m.generateMessage([]string{"recv@email.com"}, "test subject", "this is the body\n")
|
||||||
test.AssertNotError(t, err, "Failed to generate email body")
|
test.AssertNotError(t, err, "Failed to generate email body")
|
||||||
message := string(messageBytes)
|
message := string(messageBytes)
|
||||||
|
|
@ -44,8 +46,7 @@ func TestGenerateMessage(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFailNonASCIIAddress(t *testing.T) {
|
func TestFailNonASCIIAddress(t *testing.T) {
|
||||||
fc := clock.NewFake()
|
m := New("", "", "", "", "send@email.com")
|
||||||
m := MailerImpl{From: "send@email.com", clk: fc, csprgSource: fakeSource{}}
|
|
||||||
_, err := m.generateMessage([]string{"遗憾@email.com"}, "test subject", "this is the body\n")
|
_, err := m.generateMessage([]string{"遗憾@email.com"}, "test subject", "this is the body\n")
|
||||||
test.AssertError(t, err, "Allowed a non-ASCII to address incorrectly")
|
test.AssertError(t, err, "Allowed a non-ASCII to address incorrectly")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue