无法保存邮件,引发错误

时间:2018-08-14 06:01:22

标签: c# web-services email

我正在使用以下方法保存邮件,但会引发以下错误

“必须先加载或分配此属性,然后才能读取其值”

public static string saveEmail(EmailMessage Message, string dirPath, bool withTimeStamp)
{
    string filePath;
    try
    {
        Message.Load(new PropertySet(ItemSchema.MimeContent));
        var mimeContent = Message.MimeContent;
        filePath = string.Empty;
        string mess = Message.Subject; //at this line it is giving error
        if (withTimeStamp)
        {
            filePath = dirPath + "\\" + Message.Subject.Replace(":", "") + "_" + DateTime.Now.ToString("ddMMyyyy_HHmmss") + ".msg";
        }
        else
        {
            filePath = dirPath + "\\" + Message.Subject.Replace(":", "") + ".msg";
        }
        using (var fileStream = new FileStream(filePath, FileMode.Create))
        {
            fileStream.Write(mimeContent.Content, 0, mimeContent.Content.Length);
        }

    }
    catch { throw; }
    finally { }
    return filePath;
}

让我知道是否有任何简单的解决方案,或者还有其他方法可以保存电子邮件。

0 个答案:

没有答案