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
435c0e43
Commit
435c0e43
authored
Apr 30, 2019
by
Stephan Handuwala
🏋🏻
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into 'master'
remove panic and STD output See merge request
!11
parents
202eb0f5
d5461c49
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
23 deletions
+42
-23
config.yaml
config.yaml
+6
-6
worker.go
worker.go
+36
-17
No files found.
config.yaml
View file @
435c0e43
couchdb
:
couchdb
:
port
:
'
84'
port
:
'
59
84'
host
:
couchdb_emanger
host
:
couchdb_emanger
username
:
root
username
:
root
password
:
root
password
:
root
curl
:
curl
:
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
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:84/outbox/
get_outbox_mail
:
http://root:root@couchdb_emanger:
59
84/outbox/
delete_outbox_mail
:
http://root:root@couchdb_emanger:84/outbox/
delete_outbox_mail
:
http://root:root@couchdb_emanger:
59
84/outbox/
add_sent_mail
:
http://root:root@couchdb_emanger:84/sentitems/
add_sent_mail
:
http://root:root@couchdb_emanger:
59
84/sentitems/
add_mail_log
:
http://root:root@couchdb_emanger:84/mail_logs/
add_mail_log
:
http://root:root@couchdb_emanger:
59
84/mail_logs/
protocols
:
protocols
:
method
:
http://
method
:
http://
requests
:
requests
:
...
...
worker.go
View file @
435c0e43
...
@@ -154,7 +154,8 @@ func main() {
...
@@ -154,7 +154,8 @@ func main() {
if
reqErr
!=
nil
{
if
reqErr
!=
nil
{
alert
:=
" Error creating request to OUTBOX DB
\n
"
+
reqErr
.
Error
()
alert
:=
" Error creating request to OUTBOX DB
\n
"
+
reqErr
.
Error
()
alertAdmin
(
alert
)
alertAdmin
(
alert
)
panic
(
reqErr
)
fmt
.
Printf
(
"Error : %s"
,
reqErr
.
Error
())
//panic(reqErr)
}
}
req
.
Header
.
Set
(
config
.
Requests
.
HeaderType
,
config
.
Requests
.
HeaderJson
)
req
.
Header
.
Set
(
config
.
Requests
.
HeaderType
,
config
.
Requests
.
HeaderJson
)
...
@@ -162,7 +163,8 @@ func main() {
...
@@ -162,7 +163,8 @@ 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
)
panic
(
respErr
)
fmt
.
Printf
(
"Error : %s"
,
reqErr
.
Error
())
//panic(respErr)
}
}
defer
resp
.
Body
.
Close
()
defer
resp
.
Body
.
Close
()
respbody
,
_
:=
ioutil
.
ReadAll
(
resp
.
Body
)
respbody
,
_
:=
ioutil
.
ReadAll
(
resp
.
Body
)
...
@@ -277,11 +279,13 @@ func worker(i int) {
...
@@ -277,11 +279,13 @@ func worker(i int) {
var
config
Config
var
config
Config
source
,
sourceErr
:=
ioutil
.
ReadFile
(
"config.yaml"
)
source
,
sourceErr
:=
ioutil
.
ReadFile
(
"config.yaml"
)
if
sourceErr
!=
nil
{
if
sourceErr
!=
nil
{
panic
(
sourceErr
)
fmt
.
Printf
(
"sourceErr : %s"
,
sourceErr
.
Error
())
//panic(sourceErr)
}
}
configErr
:=
yaml
.
Unmarshal
(
source
,
&
config
)
configErr
:=
yaml
.
Unmarshal
(
source
,
&
config
)
if
configErr
!=
nil
{
if
configErr
!=
nil
{
panic
(
configErr
)
fmt
.
Printf
(
"configErr : %s"
,
configErr
.
Error
())
//panic(configErr)
}
}
//fmt.Println("Worker ", i, " strats working")
//fmt.Println("Worker ", i, " strats working")
...
@@ -352,7 +356,8 @@ func worker(i int) {
...
@@ -352,7 +356,8 @@ func worker(i int) {
//if(attachErr != nil)
//if(attachErr != nil)
//attchResp, err := http.DefaultClient.Do(attachReq)
//attchResp, err := http.DefaultClient.Do(attachReq)
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
err
)
fmt
.
Printf
(
"attchResp : %s"
,
err
.
Error
())
// panic(err)
}
}
defer
attchResp
.
Body
.
Close
()
defer
attchResp
.
Body
.
Close
()
respbody
,
_
:=
ioutil
.
ReadAll
(
attchResp
.
Body
)
respbody
,
_
:=
ioutil
.
ReadAll
(
attchResp
.
Body
)
...
@@ -362,20 +367,24 @@ func worker(i int) {
...
@@ -362,20 +367,24 @@ func worker(i int) {
dec
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
resp
)
dec
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
resp
)
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
err
)
fmt
.
Printf
(
"Decode err : %s"
,
err
.
Error
())
//panic(err)
}
}
f
,
err
:=
os
.
Create
(
filename
)
f
,
err
:=
os
.
Create
(
filename
)
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
err
)
fmt
.
Printf
(
"File err : %s"
,
err
.
Error
())
//panic(err)
}
}
//defer f.Close()
//defer f.Close()
if
_
,
err
:=
f
.
Write
(
dec
);
err
!=
nil
{
if
_
,
err
:=
f
.
Write
(
dec
);
err
!=
nil
{
panic
(
err
)
fmt
.
Printf
(
"File write err : %s"
,
err
.
Error
())
// panic(err)
}
}
if
err
:=
f
.
Sync
();
err
!=
nil
{
if
err
:=
f
.
Sync
();
err
!=
nil
{
panic
(
err
)
fmt
.
Printf
(
"Sync err : %s"
,
err
.
Error
())
//panic(err)
}
}
//message.AddHeader("Content-Type", "multipart/form-data")
//message.AddHeader("Content-Type", "multipart/form-data")
...
@@ -390,6 +399,7 @@ func worker(i int) {
...
@@ -390,6 +399,7 @@ func worker(i int) {
MailgunResp
,
id
,
err
:=
mg
.
Send
(
ctx
,
message
)
MailgunResp
,
id
,
err
:=
mg
.
Send
(
ctx
,
message
)
if
err
!=
nil
{
if
err
!=
nil
{
// log.Fatal(err)
// log.Fatal(err)
fmt
.
Printf
(
"MailgunResp err : %s"
,
err
.
Error
())
alertAdmin
(
" MAilgun Error
\n
"
+
err
.
Error
())
alertAdmin
(
" MAilgun Error
\n
"
+
err
.
Error
())
}
}
if
len
(
filename
)
>
0
{
if
len
(
filename
)
>
0
{
...
@@ -447,6 +457,7 @@ func sendMessage(mg mailgun.Mailgun, sender, subject, body, recipient, cc string
...
@@ -447,6 +457,7 @@ 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
(
"MAilgun Error : %s"
,
err
.
Error
())
alertAdmin
(
" MAilgun Error
\n
"
+
err
.
Error
())
alertAdmin
(
" MAilgun Error
\n
"
+
err
.
Error
())
}
}
//fmt.Println(resp)
//fmt.Println(resp)
...
@@ -454,11 +465,13 @@ func sendMessage(mg mailgun.Mailgun, sender, subject, body, recipient, cc string
...
@@ -454,11 +465,13 @@ func sendMessage(mg mailgun.Mailgun, sender, subject, body, recipient, cc string
var
config
Config
var
config
Config
source
,
sourceErr
:=
ioutil
.
ReadFile
(
"config.yaml"
)
source
,
sourceErr
:=
ioutil
.
ReadFile
(
"config.yaml"
)
if
sourceErr
!=
nil
{
if
sourceErr
!=
nil
{
panic
(
sourceErr
)
fmt
.
Printf
(
"Mail config err : %s"
,
sourceErr
.
Error
())
// panic(sourceErr)
}
}
configErr
:=
yaml
.
Unmarshal
(
source
,
&
config
)
configErr
:=
yaml
.
Unmarshal
(
source
,
&
config
)
if
configErr
!=
nil
{
if
configErr
!=
nil
{
panic
(
configErr
)
fmt
.
Printf
(
"configErr : %s"
,
configErr
.
Error
())
// panic(configErr)
}
}
if
config
.
AppMod
.
Production
==
"0"
{
if
config
.
AppMod
.
Production
==
"0"
{
...
@@ -475,11 +488,13 @@ func alertAdmin(err string) {
...
@@ -475,11 +488,13 @@ func alertAdmin(err string) {
var
config
Config
var
config
Config
source
,
sourceErr
:=
ioutil
.
ReadFile
(
"config.yaml"
)
source
,
sourceErr
:=
ioutil
.
ReadFile
(
"config.yaml"
)
if
sourceErr
!=
nil
{
if
sourceErr
!=
nil
{
panic
(
sourceErr
)
fmt
.
Printf
(
"Admin Alert err : %s"
,
sourceErr
.
Error
())
// panic(sourceErr)
}
}
configErr
:=
yaml
.
Unmarshal
(
source
,
&
config
)
configErr
:=
yaml
.
Unmarshal
(
source
,
&
config
)
if
configErr
!=
nil
{
if
configErr
!=
nil
{
panic
(
configErr
)
fmt
.
Printf
(
"Unmarshal err : %s"
,
configErr
.
Error
())
// panic(configErr)
}
}
// sending mail via Mailgun
// sending mail via Mailgun
...
@@ -499,11 +514,13 @@ func logmail(subject, sender, recipient, cc, bcc, attachment, readTimeOutbox, ma
...
@@ -499,11 +514,13 @@ func logmail(subject, sender, recipient, cc, bcc, attachment, readTimeOutbox, ma
var
config
Config
var
config
Config
source
,
sourceErr
:=
ioutil
.
ReadFile
(
"config.yaml"
)
source
,
sourceErr
:=
ioutil
.
ReadFile
(
"config.yaml"
)
if
sourceErr
!=
nil
{
if
sourceErr
!=
nil
{
panic
(
sourceErr
)
fmt
.
Printf
(
"Logmail sourceErr : %s"
,
sourceErr
.
Error
())
// panic(sourceErr)
}
}
configErr
:=
yaml
.
Unmarshal
(
source
,
&
config
)
configErr
:=
yaml
.
Unmarshal
(
source
,
&
config
)
if
configErr
!=
nil
{
if
configErr
!=
nil
{
panic
(
configErr
)
fmt
.
Printf
(
"Unmarshal configErr : %s"
,
configErr
.
Error
())
// panic(configErr)
}
}
logBody
:=
strings
.
NewReader
(
`{"Mail Subject":"`
+
subject
+
logBody
:=
strings
.
NewReader
(
`{"Mail Subject":"`
+
subject
+
...
@@ -539,11 +556,13 @@ func sentmail(subject, sender, recipient, cc, bcc, attachment, body, mailID stri
...
@@ -539,11 +556,13 @@ func sentmail(subject, sender, recipient, cc, bcc, attachment, body, mailID stri
var
config
Config
var
config
Config
source
,
sourceErr
:=
ioutil
.
ReadFile
(
"config.yaml"
)
source
,
sourceErr
:=
ioutil
.
ReadFile
(
"config.yaml"
)
if
sourceErr
!=
nil
{
if
sourceErr
!=
nil
{
panic
(
sourceErr
)
fmt
.
Printf
(
"Sentmail sourceErr : %s"
,
sourceErr
.
Error
())
// panic(sourceErr)
}
}
configErr
:=
yaml
.
Unmarshal
(
source
,
&
config
)
configErr
:=
yaml
.
Unmarshal
(
source
,
&
config
)
if
configErr
!=
nil
{
if
configErr
!=
nil
{
panic
(
configErr
)
fmt
.
Printf
(
"Sentmail configErr : %s"
,
configErr
.
Error
())
// panic(configErr)
}
}
sentBody
:=
strings
.
NewReader
(
`{"Mail Subject":"`
+
subject
+
sentBody
:=
strings
.
NewReader
(
`{"Mail Subject":"`
+
subject
+
...
...
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