email service added
This commit is contained in:
parent
67a881d800
commit
07f2d90490
14
glide.yaml
Normal file
14
glide.yaml
Normal file
|
@ -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
|
96
proxy/email/email_service.go
Normal file
96
proxy/email/email_service.go
Normal file
|
@ -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
|
||||
}
|
||||
|
12
proxy/email/email_service_test.go
Normal file
12
proxy/email/email_service_test.go
Normal file
|
@ -0,0 +1,12 @@
|
|||
package email
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"log"
|
||||
)
|
||||
|
||||
func TestEmailSendForAuth(t *testing.T) {
|
||||
err := EmailSendForAuth("geek@loafle.com")
|
||||
|
||||
log.Println(err)
|
||||
}
|
Loading…
Reference in New Issue
Block a user