0 votes

I want to create a mail and save/upload it as draft. Is there a sample code for this or a guide. This is very relevant in my case. Thank you!!!

by

1 Answer

0 votes
 
Best answer

You'll need to use IMAP for that.

You can use CommonFolders class to get the Drafts folder name, or you can use string name if you know it (e.g. "[Gmail]/Drafts").

First we create a message:

MailBuilder builder = new MailBuilder();
builder.Subject = "subject";
builder.From.Add(new MailBox("alice@email.com", "Alice"));
builder.To.Add(new MailBox("bob@email.com", "Bob"));
builder.Text = "This is plain text email";
IMail email = builder.Create();

Then connect to IMAP, select draft folder and upload the message:

using (Imap imap = new Imap())
{
    imap.Connect("imap.example.com");    // or ConnectSSL for SSL
    imap.UseBestLogin("user", "password");

    CommonFolders folders = new CommonFolders(imap.GetFolders());

    imap.UploadMessage(folders.Draft, email);

    // -or- imap.UploadMessage("[Gmail]/Drafts", email);

    imap.Close();
}
by (301k points)
...