'Gmail API: put email in draft and set "request Read Receipt" flag

I made this tiny piece of .NET software that takes a PDF, splits it into pages and create several draft emails on Gmail using official APIs, ready to be checked and sent.

This is the method that takes a GmailService object and create the draft:

private void CreateDraft(GmailService gmailService, MailDraft mailDraft)
{
    var mailMessage = new System.Net.Mail.MailMessage();
    
    mailMessage.To.Add(mailDraft.Recipients);
    mailMessage.Subject = mailDraft.Subject;
    mailMessage.Body = mailDraft.Body + "\r\n" + mailDraft.Signature;

    foreach (System.Net.Mail.Attachment attachment in mailDraft.Attachments)
    {
        mailMessage.Attachments.Add(attachment);
    }

    var mimeMessage = MimeKit.MimeMessage.CreateFromMailMessage(mailMessage);

    // Add Read Receipt request
    if(mailDraft.RequestReadReceipt)
    {
        // Note that this is correctly filled
        Profile currentUserProfile = gmailService.Users.GetProfile("me").Execute();
        string currentUserEmail = currentUserProfile.EmailAddress;

        mimeMessage.Headers.Add("Disposition-Notification-To", currentUserEmail);
    }

    var draft = new Draft
    {
        Message = new Google.Apis.Gmail.v1.Data.Message {
            Raw = Encode(mimeMessage)
        }
    };

    Draft createdDraft = gmailService.Users.Drafts.Create(draft, "me").Execute();
}

internal class MailDraft
{
    public string Recipients { get; set; }
    public string Subject { get; set; }
    public string Body { get; set; }
    public string Signature { get; set; }

    public List<System.Net.Mail.Attachment> Attachments { get; set; }
    public bool RequestReadReceipt { get; set; }
}

As you can see in the code, I set an header in mimeMessage to request Read Receipt, this is the Disposition-Notification-To, with value equal to the current user email address.

Unfortunately, when I open the saved draft in Gmail, it has not the request Read Receipt set to on:

Gmail

Note that this perfectly works if I send the email instead of saving it to draft (i.e. the read confirmation is requested on the other side).

Any idea?



Solution 1:[1]

When adding a custom MIME Header to the message and inserting it as a Draft using GMail API, it ends by stripping the additional header from the message.

I would recommend reporting it as a Feature Request in the Issue Tracker however there is one already opened requesting the same feature. You can check it here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Gustavo