Skip to content

Commit

Permalink
Merge pull request #16 from tbabej/fix_smtp_override
Browse files Browse the repository at this point in the history
Various SMTP-related fixes
  • Loading branch information
ddvk authored Nov 2, 2020
2 parents 7eb9dc1 + 78ecb8c commit 25bfc2f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,18 @@ In order to get hwr running with myScript register for a developer account and s
`RMAPI_HWR_HMAC`

# Sending emails
Define the following env variables (only gmail has been tested):
Define the following env variables:

`RM_SMTP_SERVER` e.g. smtp.gmail.com:465
`RM_STMP_USERNAME`
`RM_STMP_PASSWORD` (colud try with app password)
```
RM_SMTP_SERVER=smtp.gmail.com:465
RM_SMTP_USERNAME=user@domain.com
RM_SMTP_PASSWORD=plaintextpass # Application password should work
```

If you want to provide custom FROM header for your mails, you can use:
```
RM_SMTP_FROM='"ReMarkable self-hosted" <user@domain.com>'
```

# Prerequisites / Device Modifications

Expand All @@ -58,7 +65,7 @@ Install a root CA on the device, you can use the `device/gencert.sh` script
- stop xochitl `systemctl stop xochitl`
- add to /etc/hosts
```
127.0.0.1 hwr-production-dot-remarkable-production.appspot.com
127.0.0.1 hwr-production-dot-remarkable-production.appspot.com
127.0.0.1 service-manager-production-dot-remarkable-production.appspot.com
127.0.0.1 local.appspot.com
127.0.0.1 my.remarkable.com
Expand Down
12 changes: 10 additions & 2 deletions internal/email/smtp.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func init() {
if servername == "" {
log.Warnln("smtp not configured, no emails will be sent")
}
fromOverride = os.Getenv("RM_STMTP_FROM")
fromOverride = os.Getenv("RM_SMTP_FROM")
}

type EmailBuilder struct {
Expand Down Expand Up @@ -119,7 +119,7 @@ func (b *EmailBuilder) Send() (err error) {
}
delimeter := "**=myohmy689407924327898338383"
//basic email headers
msg := fmt.Sprintf("From: %s\r\n", b.From)
msg := fmt.Sprintf("From: %s\r\n", from)
msg += fmt.Sprintf("To: %s\r\n", b.To)
msg += fmt.Sprintf("Subject: %s\r\n", b.Subject)
// msg += fmt.Sprintf("ReplyTo: %s\r\n", b.ReplyTo)
Expand Down Expand Up @@ -160,6 +160,14 @@ func (b *EmailBuilder) Send() (err error) {
return err
}
}

// Add last boundary delimeter, with trailing -- according to RFC 1341
last_boundary := fmt.Sprintf("\r\n--%s--\r\n", delimeter)
_, err = w.Write([]byte(last_boundary))
if err != nil {
return err
}

err = w.Close()
if err != nil {
return err
Expand Down

0 comments on commit 25bfc2f

Please sign in to comment.