You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

C#使用Exchange发送带附件邮件触发“No mailbox with such guid”错误

解决Exchange发送带附件邮件时的“No mailbox with such guid”异常

以下是针对该问题的几种可行解决思路:

  • 验证附件路径的正确性
    先确认附件文件确实存在且路径无误,避免因文件找不到导致Exchange处理异常。建议用Path.Combine拼接路径,并提前校验文件存在性:

    string attachmentPath = Path.Combine(AppContext.BaseDirectory, "Logo.jpg");
    if (!File.Exists(attachmentPath))
    {
        throw new FileNotFoundException("无法找到附件文件", attachmentPath);
    }
    msg.Attachments.AddFileAttachment(attachmentPath);
    
  • 显式指定已发送文件夹ID
    无附件时Exchange可能自动识别默认已发送文件夹,但添加附件后需要明确指定目标文件夹。先绑定已发送文件夹,再传入SendAndSaveCopy方法:

    // 假设service是你的ExchangeService实例
    Folder sentFolder = Folder.Bind(service, WellKnownFolderName.SentItems);
    msg.SendAndSaveCopy(sentFolder.Id);
    

    这种方式能避免Exchange解析默认文件夹GUID时出错。

  • 拆分发送与保存操作
    尝试分开执行保存和发送操作,排查是哪个环节导致的GUID异常:

    Folder sentFolder = Folder.Bind(service, WellKnownFolderName.SentItems);
    msg.Save(sentFolder.Id);
    msg.Send();
    

    如果单独保存或发送正常,可以进一步定位问题点。

  • 调整内嵌图片的添加方式(如果是HTML内嵌图片)
    若图片是HTML邮件中要显示的内嵌图,不要用普通附件方式添加,需设置ContentID并标记为内嵌:

    string contentId = "emailLogo";
    FileAttachment inlineAttachment = msg.Attachments.AddFileAttachment(contentId, attachmentPath) as FileAttachment;
    inlineAttachment.IsInline = true;
    inlineAttachment.ContentId = contentId;
    // 对应HTML中的引用:<img src="cid:emailLogo" alt="Logo" />
    

    错误的内嵌图片处理方式可能触发Exchange的GUID解析错误。

内容的提问来源于stack exchange,提问作者KarstenS

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.23 07:06:22