debug-mailgun
This commit is contained in:
parent
0331d34afc
commit
e62f356a79
|
@ -19,18 +19,17 @@ func MailgunRest(to string, data map[string]interface{}, subject string, templat
|
|||
var mailgunAPIKey = os.Getenv("MAILGUN_API_KEY")
|
||||
var mailgunDomain = os.Getenv("MAILGUN_DOMAIN")
|
||||
|
||||
vars, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
vars = nil
|
||||
}
|
||||
|
||||
// Create payload
|
||||
payload := map[string]interface{}{
|
||||
"from": mailgunDomain + " <noreply@" + mailgunDomain + ">",
|
||||
"to": to,
|
||||
"subject": subject,
|
||||
"template": template,
|
||||
"h:X-Mailgun-Variables": string(vars),
|
||||
"from": mailgunDomain + " <noreply@" + mailgunDomain + ">",
|
||||
"to": to,
|
||||
"subject": subject,
|
||||
"template": template,
|
||||
}
|
||||
|
||||
vars, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
payload["h:X-Mailgun-Variables"] = string(vars)
|
||||
}
|
||||
|
||||
// Convert payload to JSON
|
||||
|
@ -39,6 +38,8 @@ func MailgunRest(to string, data map[string]interface{}, subject string, templat
|
|||
return err
|
||||
}
|
||||
|
||||
log.Printf("Mailgun API request payload: %s", payloadJSON)
|
||||
|
||||
// Make HTTP POST request
|
||||
client := &http.Client{}
|
||||
req, err := http.NewRequest("POST", fmt.Sprintf(apiURL, mailgunDomain), bytes.NewBuffer(payloadJSON))
|
||||
|
@ -59,12 +60,10 @@ func MailgunRest(to string, data map[string]interface{}, subject string, templat
|
|||
// Log the Mailgun API response
|
||||
responseBody, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Printf("Error reading Mailgun API response: %v", err)
|
||||
log.Printf("Error %v reading Mailgun API response: %v", err, responseBody)
|
||||
return err
|
||||
}
|
||||
|
||||
log.Printf("Mailgun API response: %s", responseBody)
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf("failed to send email, status: %d", resp.StatusCode)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user