Skip to content

Commit

Permalink
Send email with Amazon SES
Browse files Browse the repository at this point in the history
Fixed #7
  • Loading branch information
bbengfort committed Jan 6, 2018
1 parent 05e0569 commit 9c86997
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,14 @@ Write each calendar id (the associated email address) on its own line. Lines tha

### Email

If you would like to email your agenda to someone, you'll first need to setup SMTP. If you're using Gmail or Google Apps, make sure that you set your email account [to allow less secure apps](https://support.google.com/accounts/answer/6010255?hl=en).
If you would like to email your agenda to someone, you'll first need to setup SMTP. If you're using Gmail or Google Apps, make sure that you set your email account [to allow less secure apps](https://support.google.com/accounts/answer/6010255?hl=en). You can also use Amazon SES or other services with SMTP authentication to send mail.

Edit the configuration file with `daytimer config -e` or edit `~/daytimer/config.yml` with your email credentials:

```yaml
# Add the SMTP configuration to send email agendas
email:
from: "me@gmail.com"
host: "smtp.gmail.com",
port: 587,
user: "me@gmail.com",
Expand Down
8 changes: 4 additions & 4 deletions bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion daytimer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

// Version is the current release of daytimer
const Version = "0.2"
const Version = "0.3"

// New creates a daytimer and initialize the internal state.
func New() (*Daytimer, error) {
Expand Down
15 changes: 8 additions & 7 deletions email.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type Email struct {
// NewEmail creates a new email message
func NewEmail(subject string, body string, config *SMTPConfig) *Email {
return &Email{
From: "Daytimer Agenda",
From: fmt.Sprintf("Daytimer Agenda <%s>", config.From),
Subject: subject,
Body: body,
config: config,
Expand All @@ -70,7 +70,7 @@ func (e *Email) Send(to []string) error {
err := smtp.SendMail(
e.config.Addr(),
e.config.Auth(),
e.config.User, to,
e.config.From, to,
buffer.Bytes(),
)

Expand All @@ -83,11 +83,12 @@ func (e *Email) Send(to []string) error {

// SMTPConfig loads the email configuration from JSON.
type SMTPConfig struct {
UseTLS bool `json:"use_tls"`
Host string `json:"host"`
Port int `json:"port"`
User string `json:"user"`
Password string `json:"password"`
Host string `json:"host"` // SMTP Hostname
Port int `json:"port"` // SMTP Port usually 25, 465, or 587
User string `json:"user"` // Username for SMTP authentication
From string `json:"from"` // From email address (must be valid)
Password string `json:"password"` // Password for SMTP authentication
UseTLS bool `json:"use_tls"` // Use TLS for secure email
}

// Auth creates an SMTP authentication struct
Expand Down
5 changes: 4 additions & 1 deletion templates/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
# default editor to use.
editor: ""

# Add the SMTP configuration to send email agendas
# Add the SMTP configuration to send email agendas (e.g. Amazon SES or
# Google Mail). Note that from must be a valid email address and will be
# used as the sender of the email with the name "Daytimer Agenda".
email:
from: ""
host: "smtp.gmail.com"
port: 587
user: ""
Expand Down
2 changes: 1 addition & 1 deletion templates/email.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ From: {{.From}}
To: {{.To}}
Subject: {{.Subject}}
MIME-version: 1.0
Content-Type: text/html; charset=&quot;UTF-8&quot;
Content-Type: text/html;charset=utf-8


{{.Body}}

0 comments on commit 9c86997

Please sign in to comment.