This commit is contained in:
geek 2017-06-08 11:20:16 +09:00
parent d75306d489
commit 3701881461

View File

@ -1,18 +1,18 @@
package email
import (
"fmt"
"net"
"net/smtp"
"crypto/tls"
"log"
"net/mail"
"strings"
"github.com/google/uuid"
"encoding/json"
"fmt"
"git.loafle.net/overflow/commons_go/model/timestamp"
"git.loafle.net/overflow/overflow_proxy_service/proxy"
"git.loafle.net/overflow/overflow_proxy_service/proxy/member"
"git.loafle.net/overflow/commons_go/model/timestamp"
"github.com/google/uuid"
"log"
"net"
"net/mail"
"net/smtp"
"strings"
)
const (
@ -36,41 +36,37 @@ type Email struct {
ConfirmDate timestamp.Timestamp `json:"confirmDate,omitempty"`
SmtpServer string `json:"_"`
BodyMsg string `json:"_"`
}
func NewEmail(member member.Member, subject string) *Email {
if subject == ""{
if subject == "" {
subject = SUBJECT
}
return &Email{
Member:member,
From:FROM,
Subj:subject,
SmtpServer:SERVER_NAME,
Member: member,
From: FROM,
Subj: subject,
SmtpServer: SERVER_NAME,
}
}
type EmailService struct {
}
func NewEmailService() *EmailService{
func NewEmailService() *EmailService {
return &EmailService{}
}
func (es *EmailService) checkError(err error) {
if err != nil {
log.Panic(err)
}
}
func (es *EmailService) getSendMailMessage(e *Email) (string) {
to := mail.Address{"Park Byung Eun",e.Member.Email}
func (es *EmailService) getSendMailMessage(e *Email) string {
to := mail.Address{"Park Byung Eun", e.Member.Email}
from := mail.Address{"Overflow", e.From}
//body := "This is an Example Email\n with two lines \n http://localhost:8080/v1/overflow/services"
@ -83,7 +79,7 @@ func (es *EmailService) getSendMailMessage(e *Email) (string) {
message := ""
for k, v := range headers {
message += fmt.Sprintf("%s: %s\r\n",k,v)
message += fmt.Sprintf("%s: %s\r\n", k, v)
}
message += "\r\n" + BODY_MSG
@ -93,24 +89,23 @@ func (es *EmailService) getSendMailMessage(e *Email) (string) {
func (es *EmailService) generationAuthToken(e *Email) string {
var tempToken string
uuid,_ := uuid.NewRandom()
uuid, _ := uuid.NewRandom()
tempToken += strings.ToUpper(uuid.String())
return tempToken
}
func (es *EmailService)SendEmailForAuth(e *Email) (error){
to := mail.Address{"Park Byung Eun",e.Member.Email}
func (es *EmailService) SendEmailForAuth(e *Email) error {
to := mail.Address{"Park Byung Eun", e.Member.Email}
from := mail.Address{"Overflow", e.From}
message := es.getSendMailMessage(e)
host, _, _ := net.SplitHostPort(SERVER_NAME)
auth := smtp.PlainAuth("",FROM, SERVER_PASS, host)
auth := smtp.PlainAuth("", FROM, SERVER_PASS, host)
// TLS config
tlsconfig := &tls.Config {
tlsconfig := &tls.Config{
InsecureSkipVerify: true,
ServerName: host,
}