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