作为标题,MailKit是否支持发送文件?
如果是,我该怎么办?
BodyBuilder bodyBuilder = new BodyBuilder();
messageContent.Body = "<b>This is a test mail</b>";
bodyBuilder.HtmlBody = messageContent.Body;
Run Code Online (Sandbox Code Playgroud)
我试图将我的身体嵌入到健美运动员中,但是当我收到电子邮件时,它返回了一个空体.我有一个例外,如果正文是空的,它会抛出一个参数.
我正在使用MailKit/MimeKit 1.2.7(最新的NuGet版本).
我尝试通过API文档中的示例("使用BodyBuilder"部分)将图像嵌入到我的电子邮件的HTML正文中.
我当前的代码如下所示:
var builder = new BodyBuilder();
builder.HtmlBody = @"<p>Hey!</p><img src=""Image.png"">";
var pathImage = Path.Combine(Misc.GetPathOfExecutingAssembly(), "Image.png");
builder.LinkedResources.Add(pathLogoFile);
message.Body = builder.ToMessageBody();
Run Code Online (Sandbox Code Playgroud)
我可以发送此电子邮件,实际上图像已附加到电子邮件中.但它没有嵌入.
我错过了什么吗?或者这是Apple Mail的错(这是我用来接收电子邮件的电子邮件客户端)?
我很感激任何想法(非常感谢Jeffrey Stedfast提供这么棒的工具集!!).
英格玛
我正在尝试从邮件中保存附件
foreach(MimeKit.MimeEntity at message.Attachments)
{
at.WriteTo("nameFile");
}
Run Code Online (Sandbox Code Playgroud)
文件保存,但是当我打开时我得到错误文件已损坏或太大此文件的大小为88 kb,但文件大小应等于55 kb.
我认为在所有录制的消息文件中.
我如何只记录附件?
MailKit v1.2.0.0 MimeKit 1.2.0.0
我正在为我的项目使用Mailkit库(Imap).
我可以通过SmtpClient轻松发送新消息.
目前我正在挖掘如何回复特定邮件.是否可以为该回复邮件添加更多收件人?
@jstedfast感谢精彩的:)
有没有办法将MimeKit.MimeMessage转换为可以在Web浏览器中呈现的HTML?我不关心邮件附件,但希望能够在浏览器中显示邮件正文,包括嵌入的图像.我是MimeKit的新手,无法在API文档中找到任何内容.任何信息表示赞赏.
编辑:我没有找到与MimeKit本地执行此操作的方法,但我将其与HtmlAgilityPack结合以解析MimeMessage.HtmBody并修复内嵌图像.这似乎有效,除非有人有更好的主意,否则我会继续使用它.供参考,这是代码:
//////////////////////////////////////////////////////////////////////////////////////////
// use MimeKit to parse the message
//////////////////////////////////////////////////////////////////////////////////////////
MimeKit.MimeMessage msg = MimeKit.MimeMessage.Load(stream);
//////////////////////////////////////////////////////////////////////////////////////////
// use HtmlAgilityPack to parse the resulting html in order to fix inline images
//////////////////////////////////////////////////////////////////////////////////////////
HtmlAgilityPack.HtmlDocument hdoc = new HtmlAgilityPack.HtmlDocument();
hdoc.LoadHtml(msg.HtmlBody);
// find all image nodes
var images = hdoc.DocumentNode.Descendants("img");
foreach (var img in images)
{
// check that this is an inline image
string cid = img.Attributes["src"].Value;
if (cid.StartsWith("cid:"))
{
// remove the cid part of the attribute
cid = cid.Remove(0, 4);
// …Run Code Online (Sandbox Code Playgroud) 我正在使用 MailKit 从 Gmail 帐户读取邮件。效果很好。但是,我想获取消息状态,如已读、未读、重要、已加星标等。MailKit 可以吗?我似乎找不到任何关于它的信息。
这是我的代码:
var inbox = client.Inbox;
var message = inbox.GetMessage(4442);//4442 is the index of a message.
Console.WriteLine("Message Importance : {0}", message.Importance);
Console.WriteLine("Message Priority : {0}", message.Priority);
Run Code Online (Sandbox Code Playgroud)
重要性和优先级总是返回“正常”。如何找到这条消息被标记为重要或不重要?以及如何获取此消息的已读或未读状态?。
Visual Studio 2015 中的 0 代码
1 我正在使用 Mailkit 最新版本 (1.18.1.1) 从我自己的电子邮件服务器发送电子邮件。
2 电子邮件服务器具有不受信任的自签名证书。
3 我在代码中添加了以下两行,以忽略服务器证书错误:
client.ServerCertificateValidationCallback = (mysender, certificate, chain, sslPolicyErrors) => { return true; };
client.CheckCertificateRevocation = false;
Run Code Online (Sandbox Code Playgroud)
4 但我的程序仍然崩溃。
5 在电子邮件服务器日志中显示错误:
来自未知 [xxx.xxx.xxx.xxx] 的 SSL_accept 错误:连接被对等方重置
我猜这是因为服务器证书问题。因为在 Wireshark 捕获中,一旦我获得 SERVER 证书,连接就会终止。
6 我还在我的系统中安装了不受信任的电子邮件服务器证书,但问题仍然存在。
8 完整代码:
使用 (var client = new SmtpClient(new ProtocolLogger("logging.log")))
{
// For demo-purposes, accept all SSL certificates (in case the server supports STARTTLS)
client.ServerCertificateValidationCallback = (mysender, certificate, chain, sslPolicyErrors) => { return …Run Code Online (Sandbox Code Playgroud) 有没有办法只过滤带有附件的电子邮件?我正在使用这个代码
using (var client = new ImapClient())
{
client.Connect(IMAPServer, IMAPport, IMAPSSL);
client.AuthenticationMechanisms.Remove("XOAUTH2");
client.Authenticate(User, Password);
var inbox = client.Inbox;
inbox.Open(FolderAccess.ReadOnly);
//filter email with attachments only
var results = inbox.Search(SearchQuery.NotSeen.And(SearchQuery.NotDeleted));
}
Run Code Online (Sandbox Code Playgroud) 我一直在使用 Mailkit 2.15,现在尝试升级到 v3.4.1。当我升级时,它的所有依赖项都已安装,包括 System.Runtime.CompilerServices.Unsafe v4.5.3。但是当我执行代码时,出现以下异常。
13-Oct-2022 16:33:19,303 [INFO ] Mail SendEmail - System.IO.FileLoadException: Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
at System.Span`1..ctor(T[] array)
at MimeKit.Utils.ValueStringBuilder..ctor(Int32 initialCapacity)
at MimeKit.Utils.Rfc2047.Encode(FormatOptions options, Encoding charset, String text, Boolean phrase)
at MimeKit.Header.EncodeUnstructuredHeader(ParserOptions options, FormatOptions format, Encoding encoding, String field, String value)
at MimeKit.Header.EncodeAddressHeader(ParserOptions options, FormatOptions …Run Code Online (Sandbox Code Playgroud)