使用OutlookServicesClient

使用OutlookServicesClient

本文介绍了使用OutlookServicesClient Office 365的电子邮件发送带附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图发送一些电子邮件代表我的LOB应用程序的用户。我使用的是Office 365的连接服务API,这样我可以使用OAuth认证。我的code将发送电子邮件,但没有附件出现。这里是我的code的一个孤立的例子:

I'm trying to send out some e-mails on behalf of users of my LOB application. I'm using the Office 365 connected service API so that I can authenticate using OAuth. My code will send the e-mail, but no attachments show up. Here is an isolated example of my code:

    static async void SendUsingOutlookClient(CommunicationRow me, OutlookServicesClient outlook)
    {
        var m = new Message();
        m.From = ToRecipient(me.From);
        m.Body = new ItemBody { Content = me.Body };
        if (me.IsBodyHtml)
            m.Body.ContentType = BodyType.HTML;
        else
            m.Body.ContentType = BodyType.Text;
        m.Subject = me.Subject;
        m.CcRecipients.Add(me.Cc);
        m.BccRecipients.Add(me.Bcc);
        m.ToRecipients.Add(me.To);
        foreach (var attach in me.Attachments)
        {
            var file = attach.File;
            var fileversion = file.GetVersion(attach.Version);
            string fullpath = LibraryServiceImpl.GetFullNameInArchive(fileversion);
            var mattach = new FileAttachment { Name = file.Name, ContentId = attach.ContentId, ContentLocation = fullpath, ContentType = GraphicUtils.DetermineMime(Path.GetExtension(fullpath)) };
            if (file.Name.MissingText())
                mattach.Name = attach.ContentId + fileversion.FileExtension;
            m.Attachments.Add(mattach);
        }
        await outlook.Me.SendMailAsync(m, true);
    }

我使用发现这里的OutlookServicesClient的

推荐答案

我只是尝试这样做我自己,它看起来像问题是,OutlookServicesClient只是当你发送不包含附件数据。您可以在此看到自己,如果你使用Fiddler。

I just tried this myself, and it looks like the problem is that the OutlookServicesClient just doesn't include the attachment data when you do the send. You can see this yourself if you use Fiddler.

我让负责该库的乡亲知道这一点。在此期间,你可以把它合作,通过先保存该消息为草稿,然后用附件的更新,然后再送。是这样的:

I'll let the folks responsible for this library know about this. In the meantime, you can make it work by first saving the message as a draft, then updating with the attachments, then sending. Something like:

// Save to Drafts folder
await outlook.Me.AddMessageAsync(m);

foreach (var attach in me.Attachments)
{
    var file = attach.File;
    var fileversion = file.GetVersion(attach.Version);
    string fullpath = LibraryServiceImpl.GetFullNameInArchive(fileversion);
    var mattach = new FileAttachment { Name = file.Name, ContentId = attach.ContentId, ContentLocation = fullpath, ContentType = GraphicUtils.DetermineMime(Path.GetExtension(fullpath)) };
    if (file.Name.MissingText())
        mattach.Name = attach.ContentId + fileversion.FileExtension;
    m.Attachments.Add(mattach);
}

// Update with attachments
await m.UpdateAsync();
// Send the message
await m.SendAsync();

这篇关于使用OutlookServicesClient Office 365的电子邮件发送带附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 18:36