How can I download an Email using the Gmail api with Go - api

Trying to use the Go library of the Gmail API (v1) to get the raw content of a email and parse it as a byte slice {[]byte} so I can save it as an email. Any tips?

Looking at the package (https://pkg.go.dev/google.golang.org/api/gmail/v1#Message) it states:
// Raw: The entire email message in an RFC 2822 formatted and base64url
// encoded string. Returned in `messages.get` and `drafts.get` responses
// when the `format=RAW` parameter is supplied.
Get the email using the rfc822msgId. This can be grabbed from the header.
gmailMessageResposne, _ := gmail.Service.Users.Messages.Get("user#email.com", "rfc822msgid").Format("RAW").Do()
Once you have the *gmail.Message object you can decode the raw string via
decodedData, _ := base64.URLEncoding.DecodeString(gmailMessageResposne.Raw)
Then
base64.URLEncoding(decodedData, decodedData)
Finally
ioutile.WriteFile("message.eml", decodedData, os.ModePerm)
This worked for me!

Related

How to retrieve body form-data in key value pair and use it in postman test script

request body form-data
I tried the following but didnot work
pm.request.body.data
pm.request.data
Access this format
pm.request.body.formdata.get("name")
pm.request.body.formdata.get("last_name")
pm.request.body.formdata.get("other_name")
Documentation in here
formdata :PropertyList.<FormParam>
Form data parameters for this request are held in this field.
Type:
PropertyList.<FormParam>
Usage in Tests tab.

Invalid request body error when sending json string as data to an external api using CL_HTTP_CLIENT

We are facing an issue while sending json data to an external api using CL_HTTP_CLIENT.
The JSON data is produced using '/ui2/cl_json=>serialize( data = ls_body compress = abap_true pretty_name = /ui2/cl_json=>pretty_mode-camel_case )' .
when sending this JSON as data the the external api returns status 400 with response as
{ "errorCode": "INVALID_REQUEST_BODY", "message": "The request body is missing or improperly formatted. Unexpected character encountered while parsing value: \u001f. Path '', line 0, position 0." } .
we also stringyfied this JSON Data in backend as it might be due to parsing error but it didnt work.
The same stringyfied data tried to send through browser console using ajax and it did worked without any issue.
could any any one tell us how to handle this json object and send this to external api using CL_HTTP_CLIENT.
Note : JSON STRING is deeply nested .
Thanks in advance..
You can use request catcher service for getting SAP output.
Then check your output has valid json.
Check external api with rest tool like postman or SoapUI. Every developer not track guidliness may be external api has limitations.
The issue was with the unicodes in the string.
these were not accepted by the external api so removed from the string and sent to api and it did worked.
Thanks for You suggestion.

SES sends base64 characters in email body (instead of html) [ basic case]

I am having issue with html sent vis aws-ses. Every once in a while it sends base64 text in email body. I was able to capture a html that has this problem and could not figure out the issue - hoping if any one else has any idea on how to fix it.
I even created a test case to reproduce this issue.
Test case link: https://drive.google.com/file/d/1LWrnQowI4yLr1nYOSzcCF7_gH1sJ9_ht/view?usp=sharing
I am using java sdk to send email via SES and transmitting HTML to ses server but it sends base64 characters in email body as shown below:
=?UTF-8?B?PCEtLVtpZiBndGUgbXNvIDldPjx4bWw+CiAgICAgPG86T2Zm?= =?UTF-8?B?aWNlRG9jdW1lbnRTZXR0aW5ncz4KICAgICAgPG86QWxsb3dQTg==?= =?UTF-8?B?Ry8+CiAgICAgIDxvOlBpeGVsc1BlckluY2g+OTY8L286UGl4?= =?UTF-8?B?ZWxzUGVySW5jaD4KICAgICA8L286T2ZmaWNlRG9jdW1lbnRTZQ==?= =?UTF-8?B?dHRpbmdzPgogICAgPC94bWw+PCFbZW5kaWZdLS0+CjxodG1s?= =?UTF-8?B?PgogPGhlYWQ+IAogIDxtZXRhIGh0dHAtZXF1aXY9IkNvbnRlbg==?= =?UTF-8?B?dC1UeXBlIiBjb250ZW50PSJ0ZXh0L2h0bWw7IGNoYXJzZXQ9?= =?UTF-8?B?dXRmLTgiIC8+IAogIDxtZXRhIG5hbWU9InZpZXdwb3J0IiBjbw==?= =?UTF-8?B?bnRlbnQ9IndpZHRoPWRldmljZS13aWR0aCIgLz4gCiAgPCEt?= =?UTF-8?B?LVtpZiAhbXNvXT48IS0tPiAKICA8bWV0YSBodHRwLWVxdWl2PQ==?= =?UTF-8?B?IlgtVUEtQ29tcGF0aWJsZSIgY29udGVudD0iSUU9ZWRnZSIg?= =?UTF-8?B?Lz4gCiAgPCEtLTwhW2VuZGlmXS0tPiAKICA8dGl0bGU+PC90aQ==?= =?UTF-8?B?dGxlPiAKICA8c3R5bGUgaWQ9Im1lZGlhLXF1ZXJ5IiB0eXBl?= =?UTF-8?B?PSJ0ZXh0L2NzcyI+Ym9keSB7CiAgbWFyZ2luOiAwOwogIHBhZA==?= =?UTF-8?B?ZGluZzogMDsgfQoKdGFibGUsIHRyLCB0ZCB7CiAgdmVydGljYQ==?= =?UTF-8?B?

Onedrive API read files on given Link

I want to create project with Microsoft Cognitive Services working with Onedrive API.
Scenario is : User will give me an Onedrive link and my API will go files on that folder.
Is it possible?
If so, where can I find more documentation about it?
You'll want to leverage the shares API using an encoded version of the OneDrive Link.
GET ../v1.0/shares/{sharingTokenOrUrl}
Where sharingTokenOrUrl in your case is the URL encoded in the following manner:
First, use base64 encode the URL.
Convert the base64 encoded result to unpadded base64url format by
removing = characters from the end of the value, replacing / with _
and + with -.)
Append u! to be beginning of the string.
As an example, to encode a URL in C#:
string sharingUrl = "https://onedrive.live.com/redir?resid=1231244193912!12&authKey=1201919!12921!1";
string base64Value = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(sharingUrl));
string encodedUrl = "u!" + base64Value.TrimEnd('=').Replace('/','_').Replace('+','-');
Check out this documentation for a complete description of the shares endpoint.

Vb.Net Gmail API Send Message with attachment > 5Mb

On Gmail Api documentation i read that i've to make an HTTP request at "/upload/gmail/v1/users/userId/messages/send" when sending message larger then 5mb but i don't find any example how to implement this using the Client Library in .net
All the examples on the site refer to the "messages.Send" function that takes as parameter a raw message and the user id but i saw that there's another overload that also take the stream of the content to upload and the content type of it.
The problem is that i've no clue how to correctly call it.
Does anyone have successfully achived it ?
Thx for your answer
Simone
Simone, it's means that you use simple upload:
uploadType=media. For quick transfer of smaller files, for example, 5 MB or less.
You must use Multipart upload or Resumable upload (https://developers.google.com/gmail/api/guides/uploads)
You can send a post query with payload (see CURLOPT_POSTFIELDS, if use a CURL) on the https://www.googleapis.com/gmail/v1/users/me/messages/send?access_token=your_access_token&uploadType=multipart. Payload must contain json encoded message. Structure of this message for example:
$message = [
'message' => [
'raw' => str_replace(['+', '/'], ['-', '_'], base64_encode($mimeString)),
'threadId' => $yourThreadId
]
];
Variable $mimeString must contain correct mime string