Commit 181b170a authored by Stephan Handuwala's avatar Stephan Handuwala 🏋🏻

Merge branch 'master' into 'master'

context added to MG send function

See merge request stephan-parkwaylabs/go-email-worker!1
parents f70d5d2e eb9fa6ed
...@@ -9,6 +9,7 @@ package main ...@@ -9,6 +9,7 @@ package main
* - ./<file_name> * - ./<file_name>
*/ */
import ( import (
"context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
...@@ -318,7 +319,9 @@ func worker(i int) { ...@@ -318,7 +319,9 @@ func worker(i int) {
if len(cc) > 0 { if len(cc) > 0 {
message.AddCC(cc) message.AddCC(cc)
} }
MailgunResp, id, err := mg.Send(message) ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()
MailgunResp, id, err := mg.Send(ctx, message)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
//alertAdmin(" MAilgun Error \n" + err.Error()) //alertAdmin(" MAilgun Error \n" + err.Error())
...@@ -367,7 +370,9 @@ func sendMessage(mg mailgun.Mailgun, sender, subject, body, recipient, cc string ...@@ -367,7 +370,9 @@ func sendMessage(mg mailgun.Mailgun, sender, subject, body, recipient, cc string
* Add CC if cc recipiants are available * Add CC if cc recipiants are available
*/ */
if len(cc) > 0 { if len(cc) > 0 {
message.AddCC(cc) ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()
message.AddCC(ctx, cc)
} }
resp, id, err := mg.Send(message) resp, id, err := mg.Send(message)
if err != nil { if err != nil {
......
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