Does anyone have any experience with sending email through SMTP2GO? I'm learning to use JSON at the same time as trying to get an email feature added to an application.
Stripped down, this is what I've got now.
The JSON that it's sending is:
{
"template_data": {
"ticket_type": "VIP Comp (Staff)",
"event_name": "Dance Event",
"first_name": "James (Jim)"
},
"sender": "mysend@mydomain.com",
"subject": "Registration",
"template_id": "3233442",
"to": [
"Jim@MyDomain.com"
]
}
But I keep getting this response.
The model validation error says I have to pass "template_id", but it's there in the JSON.
The order of the JSON isn't supposed to matter, it it?
Any assistance is appreciated,
Thanks,
Jim
Stripped down, this is what I've got now.
SMTPSendx:
Sub sendSMTPx (pid As Int, msgType As String, fname As String, toEmail As String, ticket As String)
Dim jsonReturn As JSONParser
Dim jsonGen As JSONGenerator
Dim map1 As Map
Dim map2 As Map
Dim m As Map
Dim toLst As List
Dim datamap As Map
Dim event As String = "Dance Event"
Dim templateID As String = SMTPTemplateVIP ' "3233442"
Dim subject As String = "Registration"
Dim templateMap As Map = CreateMap("first_name":fname,"event_name":event,"ticket_type":ticket)
Dim status As String
Dim SenderSMTP As String = SMTPSender '"mysend@mydomain.com"
Dim apiKey As String = SMTPapi '"api-47478934973289472879238" ( No, not the real key :-) )
Dim SMTP2GO As String = "https://api.smtp2go.com/v3/email/send"
toLst.Initialize
datamap.initialize
map2.initialize
toLst.Add(toEmail)
map1= CreateMap("sender":SenderSMTP, "to":toLst, "subject":subject, "template_id":templateID, "template_data": templateMap)
jsonGen.Initialize(map1)
Log(jsonGen.ToPrettyString(3))
Dim j As HttpJob
j.Initialize("", Me)
j.poststring(SMTP2GO,jsonGen)
j.GetRequest.SetHeader("Content-Type", "application/json")
j.GetRequest.SetHeader("X-Smtp2go-Api-Key", apiKey)
Wait For (j) JobDone(j As HttpJob)
jsonReturn.Initialize(J.GetString)
map2 = jsonReturn.NextObject
datamap = map2.Get("data")
status = datamap.Get("succeeded")
j.Release
End Sub
The JSON that it's sending is:
{
"template_data": {
"ticket_type": "VIP Comp (Staff)",
"event_name": "Dance Event",
"first_name": "James (Jim)"
},
"sender": "mysend@mydomain.com",
"subject": "Registration",
"template_id": "3233442",
"to": [
"Jim@MyDomain.com"
]
}
But I keep getting this response.
Response:
ResponseError. Reason: Bad Request, Response: {"request_id": "33059300-d108-11ef-8c06-f23c92160e3c",
"data": {"error": "An error occurred processing the json data you sent with the request.
Please make sure the data conforms to the specification for this call
(see the documentation here: https://developers.smtp2go.com/reference/introduction-1)
and try again. Don't forget to set Content-Type to 'application/json'.",
"error_code": "E_ApiResponseCodes.NON_VALIDATING_IN_PAYLOAD",
"model_validation_errors": "Model Validation failed:
Either 'text_body', 'html_body' or 'template_id' must be passed"}}
The order of the JSON isn't supposed to matter, it it?
Any assistance is appreciated,
Thanks,
Jim