Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Rest API can't send email
Message
 
To
29/01/2024 11:13:19
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01687595
Message ID:
01687597
Views:
47
>I use West Wind Client Tools
>
>This is the structure that I have to follow for sending mail with SMTP2GO (email service) with their REST API
>
>
>*!*	{
>*!*	    "api_key": "api-40246460336B11E6AA53F23C91285F72",
>*!*	    "to": ["Test Person <test@example.com>"],
>*!*	    "sender": "Test Persons Friend <test2@example.com>",
>*!*	    "subject": "Hello Test Person",
>*!*	    "text_body": "You're my favorite test person ever",
>*!*	    "html_body": "<h1>You're my favorite test person ever</h1>",
>*!*	    "custom_headers": [
>*!*	      {
>*!*	        "header": "Reply-To",
>*!*	        "value": "Actual Person <test3@example.com>"
>*!*	      }
>*!*	    ],
>*!*	    "attachments": [
>*!*	        {
>*!*	            "filename": "test.pdf",
>*!*	            "fileblob": "--base64-data--",
>*!*	            "mimetype": "application/pdf"
>*!*	        },
>*!*	        {
>*!*	            "filename": "test.txt",
>*!*	            "fileblob": "--base64-data--",
>*!*	            "mimetype": "text/plain"
>*!*	        }
>*!*	    ]
>*!*	}
>
>
>Everything works well sending emails as long as I don't specify an attachment
>
>This is what I tried as for sending an attachment (PDF file).
>
>
>lcFilePath = "Costs_Preprocess.pdf"	
>lcBase64 = FILETOSTR(lcFilePath)	&& Read the contents of the file into a string
>lcBase64 = STRCONV(lcBase64, 13)        && STRCONV with 13 parameter means Base64 encoding 
>STRTOFILE(lcBase64, "Costs.pdf")
>
>
>TEXT TO lcJson
>{
>    "api_key": "api-40246460336B11E6AA53F23C91285F72",
>    "to": ["Moi <info@gestion-beaute.com>"],
>    "sender": "Encore moi <testmlm@gestion-beaute.com>",
>    "subject": "#1 Hello à moi",
>    "text_body": "Je peux juste espérer.",
>    "custom_headers": [
>      {
>        "header": "Reply-To",
>        "value": "Denis Chassé <d.chasse@gestion-beaute.com>"
>      }
>    ],
>    "attachments": [
>        {
>            "filename": "Costs.pdf",
>            "fileblob": "--base64-data--",
>            "mimetype": "application/pdf"
>        }
>    ]
>}
>ENDTEXT 
>
>loProxy = CREATEOBJECT("wwJsonServiceClient")
>lcJson = loProxy.CallService("https://api.smtp2go.com/v3/email/send",lcJson,"POST")
>loProxy = null 
>
>
>This is the error message I received.
>
>{"request_id": "cbe76704-beb9-11ee-8cdc-f23c9216ce11", "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://apidoc.smtp2go.com/documentation/#/README) and try again. Don't forget to set Content-Type to 'application/json'.", "error_code": "E_ApiResponseCodes.NON_VALIDATING_IN_PAYLOAD", "field_validation_errors": {"fieldname": "fileblob", "message": "The field 'fileblob' was expecting a base64 encoded value but instead found '--base64-data--', Please correct your JSON payload and try again."}}}
>
>
>I tried replacing
>
>
>"fileblob": "--base64-data--",
>
>with
>
>"fileblob": "base64 encoded",
>
>
>Didn't work. At this point I guess that you know that I'm out of ideas :-)
>
>I looked for "base64 encoded" related to "Visual FoxPro" on the web. Nothing to really help me.
>
>Suggestions?

I think (not sure) this line
"fileblob": "--base64-data--"
"fileblob": "<<lcBase64>>"
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Reply
Map
View

Click here to load this message in the networking platform