summaryrefslogtreecommitdiff
path: root/config.go
diff options
context:
space:
mode:
authorNikolaus Gotsche <n@softwarefools.com>2018-02-21 03:25:05 +0100
committerNikolaus Gotsche <n@softwarefools.com>2018-02-21 03:25:05 +0100
commit27b333a73524b9a99145f0ca1f2a3a0181145351 (patch)
tree23f26f7a9a31bd72b3664e684ed7d4a96441e8d3 /config.go
Mass Mailer - Send an email.html to all recipients in a maillist.csvHEADmaster
Diffstat (limited to 'config.go')
-rw-r--r--config.go129
1 files changed, 129 insertions, 0 deletions
diff --git a/config.go b/config.go
new file mode 100644
index 0000000..d371bc9
--- /dev/null
+++ b/config.go
@@ -0,0 +1,129 @@
+package main
+
+import (
+ "bytes"
+ "fmt"
+ "os"
+ "io/ioutil"
+ "strconv"
+ "github.com/BurntSushi/toml"
+)
+
+type Config struct {
+ Mailacc MailAccount `toml:"MailAccount"`
+ Massmail MassMail `toml:"MassMail"`
+}
+type MailAccount struct {
+ Address string //`toml:"address"`
+ Name string //`toml:"name"`
+ Smtpurl string //`toml:"smtpurl"`
+ Port int //`toml:"port"`
+ Accountname string //`toml:"accountname"`
+ Accountpwd string //`toml:"accountpwd"`
+}
+type MassMail struct {
+ Listfile string //`toml:"listfile"`
+ Mailfile string //`toml:"mailfile"`
+ Bannerfile string //`toml:"bannerfile"`
+ Anrede []string //`toml:"anrede"`
+ Subject string //`toml:"subject"`
+}
+
+var config Config
+
+func initConf() {
+ goodconf := false
+ for !goodconf {
+ if _, err := toml.DecodeFile("myconfig.toml", &config); err != nil {
+ fmt.Println(err)
+ makeNewTOML(false)
+ }else{
+ showConfig()
+ //fmt.Println("Loaded Config:\n",config)
+ if isSure("Is this Configuration Correct?") {
+ goodconf = true
+ }else{
+ if isSure("Enter new Configuration?"){
+ makeNewTOML(true)
+ }else{
+ fmt.Println("I Really Dont think I can Help You then...! Goodbye.")
+ os.Exit(0)
+ }
+ }
+
+ }
+ }
+}
+
+func makeNewTOML(gibts bool) {
+ if gibts {
+ fmt.Println("Editing Configuration File\nPress [Enter] to keep the Current setting")
+ }else{
+ fmt.Println("Making new Configuration File")
+
+ arr := []string{"", "", ""}
+ ma0 := MailAccount{"","","",0,"",""}
+ mm0 := MassMail{"","","",arr,""}
+ config = Config{ma0,mm0}
+ }
+ fmt.Println("Enter properties of the Send-account\n")
+ email := getNewInput("Email Account to send from: ",config.Mailacc.Address)
+ mailname := getNewInput("Name for this Account: ",config.Mailacc.Name)
+ smtpurl := getNewInput("URL of the SMTP server: ",config.Mailacc.Smtpurl)
+ port := 0
+ var err error
+ if gibts {
+ fmt.Println("Current:",config.Mailacc.Port)
+ }
+ for{
+ strport := getInput("Port of the SMTP Server: ")
+ port,err = strconv.Atoi(strport)
+ if err != nil {
+ fmt.Println(" Please insert a valid Port number!!!")
+ }else {break}
+ }
+ logname := getNewInput("Login name of the Account: ",config.Mailacc.Accountname)
+ logpwd := Encrypt(getInput("Password of the Account: "))
+
+ ma := MailAccount{email,mailname,smtpurl,port,logname,logpwd}
+
+ fmt.Println("\nEnter properties of the Mass Mail\n")
+ listfile := getNewInput("Which .csv file should be used?: ",config.Massmail.Listfile)
+ mailfile := getNewInput("What .html template to use?: ",config.Massmail.Mailfile)
+ bannerfile := getNewInput("Name of the banner image: ",config.Massmail.Bannerfile)
+ subject := getNewInput("Subject of the Mass Mail: ",config.Massmail.Subject)
+ if gibts {
+ fmt.Println("Current Salutations:",config.Massmail.Anrede)
+ }
+ anredemale := getInput("Salutation for a Male recipient: ")
+ anredeneut := getInput("Salutation for a unknown recipient: ")
+ anredefemale := getInput("Salutation for a Female recipient: ")
+
+ strarr := []string{anredemale, anredeneut, anredefemale}
+ mm := MassMail{listfile, mailfile, bannerfile, strarr, subject}
+ conf := Config{ma,mm}
+
+ buf := new(bytes.Buffer)
+ err = toml.NewEncoder(buf).Encode(conf)
+ if err != nil {
+ panic(err)
+ }else{
+ //fmt.Println("Conffile:\n",buf.String())
+ fmt.Println("Writing Configuration File")
+ err = ioutil.WriteFile("myconfig.toml", buf.Bytes(), 0644)
+ checkErr(err)
+ }
+
+}
+
+func showConfig() {
+ buf := new(bytes.Buffer)
+ err := toml.NewEncoder(buf).Encode(config)
+ if err != nil {
+ panic(err)
+ }else{
+ fmt.Println("Configuration:\n",buf.String())
+ }
+}
+
+