Search code examples
apigmailattachmentsend

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


Solution

  • 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