diff --git a/glide.yaml b/glide.yaml new file mode 100644 index 0000000..25a4223 --- /dev/null +++ b/glide.yaml @@ -0,0 +1,14 @@ +package: git.loafle.net/overflow/overflow_proxy_service +import: +- package: git.loafle.net/overflow/commons_go + subpackages: + - model/timestamp +- package: git.loafle.net/overflow/encryption_go +- package: git.loafle.net/overflow/overflow_api_db + subpackages: + - build/golang +- package: github.com/google/uuid +- package: golang.org/x/net + subpackages: + - context +- package: google.golang.org/grpc diff --git a/proxy/email/email_service.go b/proxy/email/email_service.go new file mode 100644 index 0000000..6f6fea9 --- /dev/null +++ b/proxy/email/email_service.go @@ -0,0 +1,96 @@ +package email + +import ( + "fmt" + "net" + "net/smtp" + "crypto/tls" + "log" + "net/mail" +) + +const ( + FROM = "geek@loafle.com" + SERVERNAME = "smtp.worksmobile.com:465" +) + +type EmailService struct { + +} + +func EmailSendForAuth(email string) (error){ + + to := mail.Address{"",email} + from := mail.Address{"", FROM} + subj := "This is the Test Email" + body := "This is an Example Email\n with two lines" + + // Setup headers + headers := make(map[string]string) + headers["From"] = from.String() + headers["To"] = to.String() + headers["Subject"] = subj + + //Setup Message + message := "" + + for k, v := range headers { + message += fmt.Sprintf("%s: %s\r\n",k,v) + } + message += "\r\n" + body + + host, _, _ := net.SplitHostPort(SERVERNAME) + auth := smtp.PlainAuth("",FROM, "@loafle@5795", host) + + // TLS config + tlsconfig := &tls.Config { + InsecureSkipVerify: true, + ServerName: host, + } + + conn, err := tls.Dial("tcp", SERVERNAME, tlsconfig) + if err != nil { + log.Panic(err) + } + + c, err := smtp.NewClient(conn, host) + if err != nil { + log.Panic(err) + } + + // Auth + if err = c.Auth(auth); err != nil { + log.Panic(err) + } + + // To && From + if err = c.Mail(from.Address); err != nil { + log.Panic(err) + } + + if err = c.Rcpt(to.Address); err != nil { + log.Panic(err) + } + + // Data + w, err := c.Data() + if err != nil { + log.Panic(err) + } + + _, err = w.Write([]byte(message)) + if err != nil { + log.Panic(err) + } + + err = w.Close() + if err != nil { + log.Panic(err) + } + + c.Quit() + + + return err +} + diff --git a/proxy/email/email_service_test.go b/proxy/email/email_service_test.go new file mode 100644 index 0000000..b7432b1 --- /dev/null +++ b/proxy/email/email_service_test.go @@ -0,0 +1,12 @@ +package email + +import ( + "testing" + "log" +) + +func TestEmailSendForAuth(t *testing.T) { + err := EmailSendForAuth("geek@loafle.com") + + log.Println(err) +}