Commit 53f2cc35 authored by Linus's avatar Linus 🤔
Browse files

Merge branch 'revert-2a6c7e14' into 'master'

Revert "Default and warnings in email_config.toml"

See merge request !4
parents dee3bf2e e305e617
Pipeline #80038 passed with stages
in 29 seconds
......@@ -3,7 +3,6 @@ package mail
import (
"errors"
"io/ioutil"
"log"
"math/rand"
"net/smtp"
"strconv"
......@@ -41,11 +40,9 @@ func GetEmail(id string) (string, error) {
}
type emailConfig struct {
Email string
Password string
SmtpServer string
Port string
Location string
Email string
Password string
Location string
}
var config emailConfig
......@@ -61,8 +58,8 @@ func Send(to string, subject string, body string) error {
"Subject: " + subject + "\n\n" +
body
err := smtp.SendMail(config.Email+":"+config.Port,
smtp.PlainAuth("", from, pass, config.Email),
err := smtp.SendMail("smtp.gmail.com:587",
smtp.PlainAuth("", from, pass, "smtp.gmail.com"),
from, []string{to}, []byte(msg))
if err != nil {
......@@ -75,26 +72,11 @@ func Send(to string, subject string, body string) error {
func LoadConfig(path string) error {
data, err := ioutil.ReadFile(path)
if err != nil {
config = emailConfig{}
log.Println("Warning: No email config found. You won't be able to send emails.")
log.Println("To fix this, please create an email_config.toml in your data folder " +
"with arguments Email, Password, Location (your apb url, like https://abgabepartner.de) " +
"SmtpServer (optional, default smtp.gmail.com) and Port (optional, default 587)")
return nil
return err
}
if _, err := toml.Decode(string(data), &config); err != nil {
return err
}
server := "smtp.gmail.com"
port := "587"
if config.SmtpServer == "" {
config.SmtpServer = server
log.Println("Email config: No SmtpServer specified. Defaulting to " + server)
}
if config.Port == "" {
config.Port = port
log.Println("Email config: No Port specified. Defaulting to " + port)
}
URL = config.Location
return nil
}
......@@ -2,6 +2,7 @@ package main
import (
"flag"
"fmt"
"git.rwth-aachen.de/h/apb/mail"
"git.rwth-aachen.de/h/apb/structs"
"log"
......@@ -58,6 +59,6 @@ func main() {
registerAll()
log.Printf("Starting server at port %s and IP %s\n", string(*portPtr), string(*ipStrPtr))
fmt.Printf("Starting server at port %s and IP %s\n", string(*portPtr), string(*ipStrPtr))
log.Fatal(http.ListenAndServe(*ipStrPtr+":"+string(*portPtr), nil))
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment