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
Merge requests
!75
Add: Message Id header to avoid spam mails
Code
Review changes
Check out branch
Download
Patches
Plain diff
Closed
Add: Message Id header to avoid spam mails
ab_Add_MSGIDForEmail
into
devbranch
Overview
0
Commits
1
Pipelines
0
Changes
2
Closed
Akshay Bharambe
requested to merge
ab_Add_MSGIDForEmail
into
devbranch
5 years ago
Overview
0
Commits
1
Pipelines
0
Changes
2
Expand
Add: Message Id header to avoid spam mails
0
0
Merge request reports
Compare
devbranch
devbranch (base)
and
latest version
latest version
d34d4bbb
1 commit,
5 years ago
2 files
+
37
−
2
Expand all files
Preferences
File browser
List view
Tree view
Compare changes
Inline
Side-by-side
Show whitespace changes
Show one file at a time
Search (e.g. *.vue) (Ctrl+P)
notificationmdl/email/email.go
+
25
−
1
Options
@@ -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)
Menu
Explore
Projects
Groups
Topics
Snippets