Using GRAPH API, I want to send mail with attachment that's over 10mb file size.

만도 (박재성) 21 Reputation points

Hello. I'm trying to send email using graph api.
The reason I use graph api, instead of other options, is that it can send mail with attachment that's has more than 10mb file size.

After researching about this, I found out that I have to create an upload session( and it's quite tricky to understand.

The goal is send an email with attachments that has more than 10mb file size.

so should I send two requests like this? and

first request :


How can tell 'sendMail' that it should refer createUploadSession before send email?

Following is my send email code, it will be very helpful, if you can be specific by giving detailed python code examples


If there's a way that's more simple than this(, please let me know!

Thanks in advanace

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,015 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Shweta Choudhary 601 Reputation points Microsoft Employee

    Try this if it helps

    Create the upload session:

    filename = 'Large File.txt'
    result =
    headers={'Authorization': 'Bearer ' + access_token},
    '@microsoft.graph.conflictBehavior': 'replace',
    'description': 'A large test file',
    'fileSystemInfo': {'@odata.type': 'microsoft.graph.fileSystemInfo'},
    'name': filename
    upload_session = result.json()
    upload_url = upload_session['uploadUrl']

    This request will return information about the setting including the URL where we will send the file chunks.

    Now calculate the number of chunks you will need to send:

    st = os.stat(filename)
    size = st.st_size
    CHUNK_SIZE = 10485760
    chunks = int(size / CHUNK_SIZE) + 1 if size % CHUNK_SIZE > 0 else 0
    The documentation recommends a 10MB chunk size for most cases, but you may want to adjust this.

    Now upload the chunks:

    with open(filename, 'rb') as fd:
    start = 0
    for chunk_num in range(chunks):
    chunk =
    bytes_read = len(chunk)
    upload_range = f'bytes {start}-{start + bytes_read - 1}/{size}'
    print(f'chunk: {chunk_num} bytes read: {bytes_read} upload range: {upload_range}')
    result = requests.put(
    'Content-Length': str(bytes_read),
    'Content-Range': upload_range
    start += bytes_read

    Follow Example 2 and 3 of this documentation to continue uploading byte ranges until the entire file has been uploaded.


    0 comments No comments