Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple Mailer #104

Merged
merged 5 commits into from
Apr 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cmd/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ type Config struct {
Server string
Tag string
}

Mail struct {
Server string
Port string
Username string
Password string
}
}

// QueuePair describes a client-server pair of queue names
Expand Down
32 changes: 32 additions & 0 deletions mail/mailer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2015 ISRG. All rights reserved
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

package mail

import (
"net/smtp"
)

type Mailer struct {
Server string
Port string
Auth smtp.Auth
From string
}

func NewMailer(server, port, username, password string) Mailer {
auth := smtp.PlainAuth("", username, password, server)
return Mailer{
Server: server,
Port: port,
Auth: auth,
From: username,
}
}

func (m *Mailer) SendMail(to []string, msg string) (err error) {
err = smtp.SendMail(m.Server+":"+m.Port, m.Auth, m.From, to, []byte(msg))
return
}
6 changes: 6 additions & 0 deletions mail/mailer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright 2015 ISRG. All rights reserved
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

package mail
7 changes: 7 additions & 0 deletions test/boulder-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,12 @@
"sa": {
"dbDriver": "sqlite3",
"dbName": ":memory:"
},

"mail": {
"server": "mail.example.com",
"port": "25",
"username": "cert-master@example.com",
"password": "password"
}
}