Skip to content
Open
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
4 changes: 4 additions & 0 deletions scraper.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ ToEmail = [email protected]
# The mail to send from.
FromEmail = [email protected]

# The mail to send from.
EmailServer = localhost:25


# The template we use for e-mail content
Template = default.tmpl

Expand Down
45 changes: 24 additions & 21 deletions scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"bytes"
"errors"
"fmt"
"github.com/PuerkitoBio/goquery"
"github.com/itkinside/itkconfig"
"log"
"math/rand"
"net/http"
Expand All @@ -17,17 +15,21 @@ import (
"syscall"
"text/template"
"time"

"github.com/PuerkitoBio/goquery"
"github.com/itkinside/itkconfig"
)

type Config struct {
Url []string
Interval int
ToEmail string
FromEmail string
UserAgent string
Template string
Debug bool
FirstRun bool
Url []string
Interval int
ToEmail string
FromEmail string
EmailServer string
UserAgent string
Template string
Debug bool
FirstRun bool
}

var config *Config
Expand All @@ -41,14 +43,15 @@ func printHelp() {
func loadConfig(filename string) error {
// We start with a default config, and edit it based on config file.
config = &Config{
Url: []string{},
Interval: 30,
ToEmail: "[email protected]",
FromEmail: "root@localhost",
UserAgent: "Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0",
Template: "default.tmpl",
Debug: false,
FirstRun: true,
Url: []string{},
Interval: 30,
ToEmail: "[email protected]",
FromEmail: "root@localhost",
EmailServer: "localhost:25",
UserAgent: "Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0",
Template: "default.tmpl",
Debug: false,
FirstRun: true,
}

// Load config from file, overwriting defaults.
Expand Down Expand Up @@ -113,9 +116,9 @@ func handleSignals() {
}()
}

func sendMail(to, from, content string) error {
func sendMail(to, from, emailServer, content string) error {
// Check that the SMTP server is OK and connect.
c, err := smtp.Dial("localhost:25")
c, err := smtp.Dial(emailServer)
if err != nil {
log.Println("Could not send e-mail, check your local SMTP-configuration. Got following error:")
return err
Expand Down Expand Up @@ -275,7 +278,7 @@ func checkFinn(url string) error {
}

// Send the actual email.
err = sendMail(config.ToEmail, config.FromEmail, content)
err = sendMail(config.ToEmail, config.FromEmail, config.EmailServer, content)
if err != nil {
return err
}
Expand Down