gpt4 book ai didi

c# - Mailkit:发送草稿

转载 作者:行者123 更新时间:2023-11-30 17:41:13 24 4
gpt4 key购买 nike

我试图在 mailkit 中找到一个在 IMAP 中执行命令“执行追加”的方法,在 C# 中我会这样做:

MailMessage mg = null;

using (ImapClient cl = new ImapClient("imap.gmail.com"))
{
cl.Port = 993;
cl.Ssl = true;
cl.UserName = "xxxxx";
cl.Password = "yyyyy";
var bl = cl.Authenticate();
if (bl == true)
{
//Add Draft
var smg = new SmtpMessage("xxx@gmail.com", "yyy@hotmail.com","yyy@hotmail.com", "This is a test mail.", "Hi.Is it correct??");
cl.ExecuteAppend("GMail/Drafts", smg.GetDataText(), "\\Draft",DateTimeOffset.Now);
}
}

但是观察 MailKit ImapClient,我没有这个选项..
我如何在 MailKit IMAP 中执行追加?

最佳答案

经过几个小时的搜索....

  using (var client = new ImapClient())
{
try
{
client.Connect(ConfigurationManager.AppSettings["ImapServer"], int.Parse(ConfigurationManager.AppSettings["ImapPort"]), SecureSocketOptions.Auto);

// Note: since we don't have an OAuth2 token, disable
// the XOAUTH2 authentication mechanism.
client.AuthenticationMechanisms.Remove("XOAUTH2");

// MailKit uses by default ntlm authentication
client.Authenticate("username", "password");


var draftFolder = client.GetFolder(SpecialFolder.Drafts);
if (draftFolder != null)
{
draftFolder.Open(FolderAccess.ReadWrite);

draftFolder.Append(message, MessageFlags.Draft);
draftFolder.Expunge();
}
else
{
var toplevel = client.GetFolder(client.PersonalNamespaces[0]);
var DraftFolder = toplevel.Create(SpecialFolder.Drafts.ToString(), true);

DraftFolder.Open(FolderAccess.ReadWrite);
DraftFolder.Append(message, MessageFlags.Draft);
DraftFolder.Expunge();
}

}
catch (Exception ex)
{
throw new ApplicationException("IMAPException has occured: " + ex.Message);
}

client.Disconnect(true);
}

关于c# - Mailkit:发送草稿,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33365072/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com