Commit e2808205 authored by Stephan Handuwala's avatar Stephan Handuwala 🏋🏻

Merge branch 'master' into 'master'

port change & new sent items function

See merge request !5
parents db314fd2 ff03e99c
couchdb:
port: '5984'
port: '84'
host: couchdb_emanger
username: root
password: root
curl:
check_mail: http://root:root@couchdb_emanger:5984/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:5984/outbox/
delete_outbox_mail: http://root:root@couchdb_emanger:5984/outbox/
add_sent_mail: http://root:root@couchdb_emanger:5984/sentitems/
add_mail_log: http://root:root@couchdb_emanger:5984/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:
......
......@@ -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,6 +405,7 @@ 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 {
......@@ -413,8 +420,9 @@ func worker(i int) {
}
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)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment