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
9710919c
Commit
9710919c
authored
May 02, 2019
by
Stephan Handuwala
🏋🏻
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into 'master'
read logs & status See merge request
!12
parents
435c0e43
0d0a8da5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
5 deletions
+50
-5
config.yaml
config.yaml
+1
-0
worker.go
worker.go
+49
-5
No files found.
config.yaml
View file @
9710919c
...
@@ -9,6 +9,7 @@ curl:
...
@@ -9,6 +9,7 @@ curl:
delete_outbox_mail
:
http://root:root@couchdb_emanger:5984/outbox/
delete_outbox_mail
:
http://root:root@couchdb_emanger:5984/outbox/
add_sent_mail
:
http://root:root@couchdb_emanger:5984/sentitems/
add_sent_mail
:
http://root:root@couchdb_emanger:5984/sentitems/
add_mail_log
:
http://root:root@couchdb_emanger:5984/mail_logs/
add_mail_log
:
http://root:root@couchdb_emanger:5984/mail_logs/
read_log
:
http://root:root@couchdb_emanger:5984/read_logs/
protocols
:
protocols
:
method
:
http://
method
:
http://
requests
:
requests
:
...
...
worker.go
View file @
9710919c
...
@@ -41,6 +41,7 @@ type Config struct {
...
@@ -41,6 +41,7 @@ type Config struct {
DeleteOutboxMail
string
`yaml:"delete_outbox_mail"`
DeleteOutboxMail
string
`yaml:"delete_outbox_mail"`
AddSentMail
string
`yaml:"add_sent_mail"`
AddSentMail
string
`yaml:"add_sent_mail"`
AddMailLog
string
`yaml:"add_mail_log"`
AddMailLog
string
`yaml:"add_mail_log"`
ReadLog
string
`yaml:"read_log"`
}
`yaml:"curl"`
}
`yaml:"curl"`
Protocols
struct
{
Protocols
struct
{
Request
string
`yaml:"method"`
Request
string
`yaml:"method"`
...
@@ -163,12 +164,12 @@ func main() {
...
@@ -163,12 +164,12 @@ func main() {
if
respErr
!=
nil
{
if
respErr
!=
nil
{
alert
:=
" Error in getting email from the OUTBOX DB
\n
"
+
respErr
.
Error
()
alert
:=
" Error in getting email from the OUTBOX DB
\n
"
+
respErr
.
Error
()
alertAdmin
(
alert
)
alertAdmin
(
alert
)
fmt
.
Printf
(
"Error : %s"
,
req
Err
.
Error
())
//fmt.Printf("Error : %s", resp
Err.Error())
//panic(respErr)
//panic(respErr)
}
}
defer
resp
.
Body
.
Close
()
defer
resp
.
Body
.
Close
()
respbody
,
_
:=
ioutil
.
ReadAll
(
resp
.
Body
)
respbody
,
_
:=
ioutil
.
ReadAll
(
resp
.
Body
)
//fmt.Println(string(respbody)
)
fmt
.
Printf
(
" %s | "
,
resp
.
Status
)
/**
/**
* struct the response of the of the cURL request
* struct the response of the of the cURL request
...
@@ -181,6 +182,17 @@ func main() {
...
@@ -181,6 +182,17 @@ func main() {
alertAdmin
(
alert
)
alertAdmin
(
alert
)
}
}
if
respErr
!=
nil
{
alert
:=
" Error in getting email from the OUTBOX DB
\n
"
+
respErr
.
Error
()
alertAdmin
(
alert
)
fmt
.
Printf
(
"Error : %s"
,
reqErr
.
Error
())
logOutbox
(
resp
.
Status
,
reqErr
.
Error
(),
newDoc
.
Rows
[
0
]
.
ID
)
//panic(respErr)
}
defer
resp
.
Body
.
Close
()
//fmt.Printf("Status - %d", resp.StatusCode)
// logOutbox()
/**
/**
* if: the "OUTBOX" DB has new records, it returns the number of Rows
* if: the "OUTBOX" DB has new records, it returns the number of Rows
* so there are new documents the value is always greaterthan 0
* so there are new documents the value is always greaterthan 0
...
@@ -400,7 +412,7 @@ func worker(i int) {
...
@@ -400,7 +412,7 @@ func worker(i int) {
if
err
!=
nil
{
if
err
!=
nil
{
// log.Fatal(err)
// log.Fatal(err)
fmt
.
Printf
(
"MailgunResp err : %s"
,
err
.
Error
())
fmt
.
Printf
(
"MailgunResp err : %s"
,
err
.
Error
())
alertAdmin
(
" M
A
ilgun Error
\n
"
+
err
.
Error
())
alertAdmin
(
" M
a
ilgun Error
\n
"
+
err
.
Error
())
}
}
if
len
(
filename
)
>
0
{
if
len
(
filename
)
>
0
{
os
.
Remove
(
filename
)
os
.
Remove
(
filename
)
...
@@ -457,8 +469,8 @@ func sendMessage(mg mailgun.Mailgun, sender, subject, body, recipient, cc string
...
@@ -457,8 +469,8 @@ func sendMessage(mg mailgun.Mailgun, sender, subject, body, recipient, cc string
resp
,
id
,
err
:=
mg
.
Send
(
ctx
,
message
)
resp
,
id
,
err
:=
mg
.
Send
(
ctx
,
message
)
if
err
!=
nil
{
if
err
!=
nil
{
//log.Fatal(err)
//log.Fatal(err)
fmt
.
Printf
(
"M
A
ilgun Error : %s"
,
err
.
Error
())
fmt
.
Printf
(
"M
a
ilgun Error : %s"
,
err
.
Error
())
alertAdmin
(
" M
A
ilgun Error
\n
"
+
err
.
Error
())
alertAdmin
(
" M
a
ilgun Error
\n
"
+
err
.
Error
())
}
}
//fmt.Println(resp)
//fmt.Println(resp)
// get configurations
// get configurations
...
@@ -585,3 +597,35 @@ func sentmail(subject, sender, recipient, cc, bcc, attachment, body, mailID stri
...
@@ -585,3 +597,35 @@ func sentmail(subject, sender, recipient, cc, bcc, attachment, body, mailID stri
defer
logResp
.
Body
.
Close
()
defer
logResp
.
Body
.
Close
()
ioutil
.
ReadAll
(
logResp
.
Body
)
ioutil
.
ReadAll
(
logResp
.
Body
)
}
}
func
logOutbox
(
status
,
error
,
id
string
)
{
// get configurations
var
config
Config
source
,
sourceErr
:=
ioutil
.
ReadFile
(
"config.yaml"
)
if
sourceErr
!=
nil
{
fmt
.
Printf
(
"Logmail sourceErr : %s"
,
sourceErr
.
Error
())
// panic(sourceErr)
}
configErr
:=
yaml
.
Unmarshal
(
source
,
&
config
)
if
configErr
!=
nil
{
fmt
.
Printf
(
"Logmail configErr : %s"
,
configErr
.
Error
())
// panic(configErr)
}
sentBody
:=
strings
.
NewReader
(
`{"status":"`
+
status
+
`","error":"`
+
error
+
`","id":"`
+
id
+
`"}`
)
logReq
,
logBodyerr
:=
http
.
NewRequest
(
config
.
Requests
.
Put
,
config
.
Curl
.
ReadLog
+
id
,
sentBody
)
if
logBodyerr
!=
nil
{
alert
:=
" Error requesting log 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 LOGS 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