email service added

This commit is contained in:
geek 2017-06-02 18:18:52 +09:00
parent 67a881d800
commit 07f2d90490
3 changed files with 122 additions and 0 deletions

14
glide.yaml Normal file
View 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

View 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
}

View File

@ -0,0 +1,12 @@
package email
import (
"testing"
"log"
)
func TestEmailSendForAuth(t *testing.T) {
err := EmailSendForAuth("geek@loafle.com")
log.Println(err)
}