Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
GO Email Worker
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Stephan Handuwala
GO Email Worker
Commits
ff03e99c
Commit
ff03e99c
authored
Apr 30, 2019
by
Pasan Mallawaarachchi
💻
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
port change & new sent items function
parent
ad8bc85d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
21 deletions
+63
-21
config.yaml
config.yaml
+6
-6
worker.go
worker.go
+57
-15
No files found.
config.yaml
View file @
ff03e99c
couchdb
:
port
:
'
59
84'
port
:
'
84'
host
:
couchdb_emanger
username
:
root
password
:
root
curl
:
check_mail
:
http://root:root@couchdb_emanger:
59
84/outbox/_all_docs/?limit=1
#http://root:root@0.0.0.0:5984/outbox/_all_docs/?limit=1
get_outbox_mail
:
http://root:root@couchdb_emanger:
59
84/outbox/
delete_outbox_mail
:
http://root:root@couchdb_emanger:
59
84/outbox/
add_sent_mail
:
http://root:root@couchdb_emanger:
59
84/sentitems/
add_mail_log
:
http://root:root@couchdb_emanger:
59
84/mail_logs/
check_mail
:
http://root:root@couchdb_emanger:84/outbox/_all_docs/?limit=1
#http://root:root@0.0.0.0:5984/outbox/_all_docs/?limit=1
get_outbox_mail
:
http://root:root@couchdb_emanger:84/outbox/
delete_outbox_mail
:
http://root:root@couchdb_emanger:84/outbox/
add_sent_mail
:
http://root:root@couchdb_emanger:84/sentitems/
add_mail_log
:
http://root:root@couchdb_emanger:84/mail_logs/
protocols
:
method
:
http://
requests
:
...
...
worker.go
View file @
ff03e99c
...
...
@@ -337,9 +337,13 @@ func worker(i int) {
*/
if
len
(
cc
)
>
0
{
message
.
AddCC
(
cc
)
}
else
{
cc
=
""
}
if
len
(
bcc
)
>
0
{
message
.
AddBCC
(
bcc
)
}
else
{
bcc
=
""
}
if
len
(
attachment
)
>
0
{
//url := "http://www.orimi.com/pdf-test.pdf"
...
...
@@ -378,6 +382,8 @@ func worker(i int) {
//message.AddHeader("Content-Type", "multipart/form-data")
message
.
AddAttachment
(
filename
)
// message.AddReaderAttachment(filename, f)
}
else
{
attachment
=
""
}
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
*
30
)
...
...
@@ -399,22 +405,24 @@ func worker(i int) {
/**
* add the email as new document in "SENT ITEMS" DB
*/
mailBody
:=
strings
.
NewReader
(
`{"from":"`
+
sender
+
`","to":"`
+
recipient
+
`","subject":"`
+
subject
+
`","body":"`
+
body
+
`","cc":"`
+
cc
+
`","bcc":"`
+
bcc
+
`","attachment":"`
+
attachment
+
`"}`
)
req
,
mailBodyerr
:=
http
.
NewRequest
(
config
.
Requests
.
Put
,
config
.
Curl
.
AddSentMail
+
mail
.
ID
,
mailBody
)
if
mailBodyerr
!=
nil
{
alert
:=
" Error requesting newmail to add in SENTITEMS DB
\n
"
+
mailBodyerr
.
Error
()
alertAdmin
(
alert
)
}
req
.
Header
.
Set
(
config
.
Requests
.
HeaderType
,
config
.
Requests
.
HeaderJson
)
resp
,
respErr
:=
http
.
DefaultClient
.
Do
(
req
)
if
respErr
!=
nil
{
alert
:=
" Error adding newmail to SENTITEMS DB
\n
"
+
respErr
.
Error
()
alertAdmin
(
alert
)
}
defer
resp
.
Body
.
Close
()
ioutil
.
ReadAll
(
resp
.
Body
)
/*
mailBody := strings.NewReader(`{"from":"` + sender + `","to":"` + recipient + `","subject":"` + subject + `","body":"` + body + `","cc":"` + cc + `","bcc":"` + bcc + `","attachment":"` + attachment + `"}`)
req, mailBodyerr := http.NewRequest(config.Requests.Put, config.Curl.AddSentMail+mail.ID, mailBody)
if mailBodyerr != nil {
alert := " Error requesting newmail to add in SENTITEMS DB \n" + mailBodyerr.Error()
alertAdmin(alert)
}
req.Header.Set(config.Requests.HeaderType, config.Requests.HeaderJson)
resp, respErr := http.DefaultClient.Do(req)
if respErr != nil {
alert := " Error adding newmail to SENTITEMS DB \n" + respErr.Error()
alertAdmin(alert)
}
defer resp.Body.Close()
ioutil.ReadAll(resp.Body)
*/
mailAddedSentitems
:=
time
.
Now
()
.
String
()
sentmail
(
subject
,
sender
,
recipient
,
cc
,
bcc
,
attachment
,
body
,
mail
.
ID
)
logmail
(
subject
,
sender
,
recipient
,
cc
,
bcc
,
attachment
,
readTimeOutbox
,
mailSentTimeMailgun
,
id
,
MailgunResp
,
mailAddedSentitems
,
deleteTimeOutbox
,
mail
.
ID
)
}
...
...
@@ -525,3 +533,37 @@ func logmail(subject, sender, recipient, cc, bcc, attachment, readTimeOutbox, ma
defer
logResp
.
Body
.
Close
()
ioutil
.
ReadAll
(
logResp
.
Body
)
}
func
sentmail
(
subject
,
sender
,
recipient
,
cc
,
bcc
,
attachment
,
body
,
mailID
string
)
{
// get configurations
var
config
Config
source
,
sourceErr
:=
ioutil
.
ReadFile
(
"config.yaml"
)
if
sourceErr
!=
nil
{
panic
(
sourceErr
)
}
configErr
:=
yaml
.
Unmarshal
(
source
,
&
config
)
if
configErr
!=
nil
{
panic
(
configErr
)
}
sentBody
:=
strings
.
NewReader
(
`{"Mail Subject":"`
+
subject
+
`","Mail sender":"`
+
sender
+
`","Mail recipiants":"`
+
recipient
+
`","Mail cc":"`
+
cc
+
`","Mail bcc":"`
+
bcc
+
`","Mail attachment":"`
+
attachment
+
`"}`
)
logReq
,
logBodyerr
:=
http
.
NewRequest
(
config
.
Requests
.
Put
,
config
.
Curl
.
AddSentMail
+
mailID
,
sentBody
)
if
logBodyerr
!=
nil
{
alert
:=
" Error requesting sent mail
\n
"
+
logBodyerr
.
Error
()
alertAdmin
(
alert
)
}
logReq
.
Header
.
Set
(
config
.
Requests
.
HeaderType
,
config
.
Requests
.
HeaderJson
)
logResp
,
respErr
:=
http
.
DefaultClient
.
Do
(
logReq
)
if
respErr
!=
nil
{
alert
:=
" Error adding data to SENT ITEMS DB
\n
"
+
respErr
.
Error
()
alertAdmin
(
alert
)
}
defer
logResp
.
Body
.
Close
()
ioutil
.
ReadAll
(
logResp
.
Body
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment