我总是使用gmail来保存网页剪辑或笔记。我只是创建一个新邮件,编辑它并保存为草稿。 2年多来,我在Gmail草稿文件夹中弃置了1000多封邮件。我想以编程方式将所有这些发送给自己。我做了一些研究,现在我可以使用python或c#通过IMAP加载我的gmail收件箱邮件,或创建邮件并通过SMTP发送。但是,我仍然无法阅读草稿信息并将其发送给自己。
(为什么我使用GMail作为笔记存储,而不是笔记应用程序,如evernote,MS onenote或Apple笔记?因为任何平台或设备都可以更好地支持电子邮件。通常有预安装的电子邮件客户端,而且&# 39;更容易找到或定义一个"创建新邮件"键盘快捷键而不是"导出到evernote"键盘快捷键。)
答案 0 :(得分:2)
如果您使用MailKit,请按以下步骤操作:
using System;
using System.Net;
using System.Threading;
using MailKit.Net.Imap;
using MailKit.Net.Smtp;
using MailKit;
using MimeKit;
namespace TestClient {
class Program
{
public static void Main (string[] args)
{
using (var client = new ImapClient ()) {
var credentials = new NetworkCredential ("jimbo", "password");
client.Connect (new Uri ("imaps://imap.gmail.com"), CancellationToken.None);
client.Authenticate (credentials, CancellationToken.None);
var folder = client.GetFolder (SpecialFolder.Drafts);
folder.Open (FolderAccess.ReadWrite, CancellationToken.None);
using (var smtp = new SmtpClient ()) {
smtp.Connect (new Uri ("smtps://smtp.gmail.com"), CancellationToken.None);
smtp.Authenticate (credentials, CancellationToken.None);
var indexes = new int[folder.Count];
for (int i = 0; i < folder.Count; i++) {
var message = folder.GetMessage (i, CancellationToken.None);
// if you haven't already specified a recipient, do it now:
message.To.Add (new MailboxAddress ("Jimbo", "jimbo@gmail.com"));
smtp.Send (message, CancellationToken.None);
indexes[i] = i;
}
// if you also want to delete the messages on the IMAP server:
folder.AddFlags (indexes, MessageFlags.Deleted, true, CancellationToken.None);
folder.Close (true, CancellationToken.None);
smtp.Disconnect (true, cancellationToken.None);
}
client.Disconnect (true, cancellationToken.None);
}
}
}
}