summaryrefslogtreecommitdiff
path: root/mails.go
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2013-08-29 22:37:05 +0200
committerKevin Chabowski <kevin@kch42.de>2013-08-29 22:37:05 +0200
commit61f137d2cc8ae0199c99493701023b4d862a34ad (patch)
tree5a77a1beb16cfd508486fabf6419f37fc348fc34 /mails.go
parent8ecfe7a2fc61caf890e319e7a2f298b71dc90826 (diff)
downloadmailremind-61f137d2cc8ae0199c99493701023b4d862a34ad.tar.gz
mailremind-61f137d2cc8ae0199c99493701023b4d862a34ad.tar.bz2
mailremind-61f137d2cc8ae0199c99493701023b4d862a34ad.zip
Registering accounts is working
Diffstat (limited to 'mails.go')
-rw-r--r--mails.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/mails.go b/mails.go
new file mode 100644
index 0000000..5e5a6dc
--- /dev/null
+++ b/mails.go
@@ -0,0 +1,52 @@
+package main
+
+import (
+ "bytes"
+ "fmt"
+ "kch42.de/gostuff/mailremind/model"
+ "log"
+ "path"
+ "text/template"
+ "time"
+)
+
+func loadMailTpl(tplroot, name string) *template.Template {
+ tpl, err := template.ParseFiles(path.Join(tplroot, name+".tpl"))
+ if err != nil {
+ log.Fatalf("Could not load mailtemplate %s: %s", name, err)
+ }
+ return tpl
+}
+
+var mailActivationcode *template.Template
+
+func initMails() {
+ tplroot, err := conf.GetString("paths", "mailtpls")
+ if err != nil {
+ log.Fatalf("Could not get paths.mailtpls from config: %s", err)
+ }
+
+ mailActivationcode = loadMailTpl(tplroot, "activationcode")
+}
+
+type activationcodeData struct {
+ URL string
+}
+
+func SendActivationcode(to, acCode string, uid model.DBID) bool {
+ buf := new(bytes.Buffer)
+ fmt.Fprintf(buf, "To: %s\n", to)
+ fmt.Fprintf(buf, "From: %s\n", MailFrom)
+ fmt.Fprintf(buf, "Subject: Activation code for your mailremind account\n")
+ fmt.Fprintf(buf, "Date: %s\n", time.Now().Format(time.RFC822))
+
+ fmt.Fprintln(buf, "")
+
+ url := fmt.Sprintf("%s/activate/U=%s&Code=%s", baseurl, uid, acCode)
+ if err := mailActivationcode.Execute(buf, activationcodeData{url}); err != nil {
+ log.Printf("Error while executing mail template (activationcode): %s", err)
+ return false
+ }
+
+ return Mail(to, MailFrom, buf.Bytes())
+}