Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
MKCLOS
Core Development Platform
corepkgv2
Commits
d34d4bbb
Commit
d34d4bbb
authored
5 years ago
by
Akshay Bharambe
Browse files
Options
Downloads
Patches
Plain Diff
Add: Message Id header to avoid spam mails
1. Add: Message Id header to avoid spam mails
parent
df5ab86d
2 merge requests
!76
Add: Message Id header to avoid spam mails
,
!75
Add: Message Id header to avoid spam mails
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
notificationmdl/email/email.go
+25
-1
notificationmdl/email/email.go
notificationmdl/email/emailSLS.go
+12
-1
notificationmdl/email/emailSLS.go
with
37 additions
and
2 deletions
notificationmdl/email/email.go
+
25
−
1
View file @
d34d4bbb
...
...
@@ -7,6 +7,8 @@ import (
"strings"
"sync"
"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/utiliymdl/guidmdl"
"gopkg.in/gomail.v2"
"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/configmdl"
...
...
@@ -51,6 +53,7 @@ type Email struct {
subject
string
attachments
[]
string
body
string
plainBody
string
}
func
NewEmail
(
to
,
cc
,
bcc
,
attachments
[]
string
,
from
,
subject
,
body
string
)
*
Email
{
...
...
@@ -127,13 +130,21 @@ func (email *Email) parseTemplateText(templateText string, templateData interfac
// Send -send email
func
(
email
*
Email
)
Send
()
error
{
domain
,
domainErr
:=
getSenderDomain
(
email
.
from
)
if
domainErr
!=
nil
{
loggermdl
.
LogError
(
"error getting domain address: "
,
domainErr
)
return
domainErr
}
message
:=
gomail
.
NewMessage
()
message
.
SetHeader
(
"From"
,
email
.
from
)
message
.
SetHeader
(
"To"
,
email
.
to
...
)
message
.
SetHeader
(
"Cc"
,
email
.
cc
...
)
message
.
SetHeader
(
"Bcc"
,
email
.
bcc
...
)
message
.
SetHeader
(
"Subject"
,
email
.
subject
)
message
.
SetBody
(
"text/html"
,
email
.
body
)
message
.
SetBody
(
"text/plain"
,
email
.
plainBody
)
message
.
SetHeader
(
"Message-ID"
,
getMSGIDHeader
(
domain
,
guidmdl
.
GetGUID
()))
message
.
AddAlternative
(
"text/html"
,
email
.
body
)
for
_
,
attachment
:=
range
email
.
attachments
{
message
.
Attach
(
attachment
)
// attach whatever you want
}
...
...
@@ -146,6 +157,19 @@ func (email *Email) Send() error {
return
nil
}
func
getMSGIDHeader
(
domain
,
guid
string
)
string
{
return
"<"
+
guid
+
"@"
+
domain
+
">"
}
func
getSenderDomain
(
from
string
)
(
string
,
error
)
{
s
:=
strings
.
Split
(
from
,
"@"
)
if
len
(
s
)
!=
2
{
return
""
,
errormdl
.
Wrap
(
"invalid email id for sender"
)
}
return
s
[
1
],
nil
}
// SendMailSMTP - send email service sends email as per the given html template and data using smtp
// func (email *Email) SendMailSMTP(templateFilePath string, templateData interface{}) error {
// err := email.parseTemplate(templateFilePath, templateData)
...
...
This diff is collapsed.
Click to expand it.
notificationmdl/email/emailSLS.go
+
12
−
1
View file @
d34d4bbb
...
...
@@ -8,6 +8,7 @@ import (
"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/errormdl"
"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/loggermdl"
"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/utiliymdl/guidmdl"
gomail
"gopkg.in/gomail.v2"
)
...
...
@@ -47,13 +48,23 @@ func (email *Email) SendMailFromSLS(hostName string) error {
config
=
tmp
}
domain
,
domainErr
:=
getSenderDomain
(
email
.
from
)
if
domainErr
!=
nil
{
loggermdl
.
LogError
(
"error getting domain address: "
,
domainErr
)
return
domainErr
}
message
:=
gomail
.
NewMessage
()
message
.
SetHeader
(
"From"
,
email
.
from
)
message
.
SetHeader
(
"To"
,
email
.
to
...
)
message
.
SetHeader
(
"Cc"
,
email
.
cc
...
)
message
.
SetHeader
(
"Bcc"
,
email
.
bcc
...
)
message
.
SetHeader
(
"Subject"
,
email
.
subject
)
message
.
SetBody
(
"text/html"
,
email
.
body
)
message
.
SetBody
(
"text/plain"
,
email
.
body
)
message
.
SetHeader
(
"Message-ID"
,
getMSGIDHeader
(
domain
,
guidmdl
.
GetGUID
()))
message
.
AddAlternative
(
"text/html"
,
email
.
plainBody
)
for
_
,
attachment
:=
range
email
.
attachments
{
message
.
Attach
(
attachment
)
// attach whatever you want
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets