开发者

.NET Outlook Add-in: attaching a sent email item to a journal entry

So I'm developing an outlook add-in that basically gathers some info from the user in the form, then sends a properly formatted email to the right person. What I want to do is then make a journal entry noting that the email had been sent, and attach the email in reference.

To accomplish this manually, I can go to the "Sent Items" folder, and simply drag the email of choice down over the Journal icon in the bottom-left menu, and this accomplishes what I'm trying to do programmatically.

Here is the code I'm using once the mail is sent:

Private Sub Application_ItemSend(ByVal Item As Object, ByRef Cancel As Boolean) Handles Application.ItemSend
    Cancel = False
    Dim sent As Outlook.MailItem = CType(Item, Outlook.MailItem)
    Dim app As New Outlook.Application

    Dim journal As Outlook.JournalItem = app.CreateItem(Outlook.OlItemType.olJournalItem)
    journal.Subject = sent.Subject & " - " & df.TextBox1.Text
    journal.Type = "E-mail Message"
    journal.Start = Now()
    journal.Duration = 0
    journal.Body = "Request sent to " & df.ComboBox4.SelectedItem.ToString()


    Try
        journal.Attachments.Add(sent, Outlook.OlAttachmentType.olByReference)
        journal.Save()
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try
    df.Close()
End Sub

Its getting hung up at Attachments.Add and my error message is "an object could not be found". I'm guessing it means 'sent' is no good. However, I use sent.Subject to title the journal entry, and I do not get an erro开发者_如何学Pythonr there. Any thoughts?

Your help is greatly valued!


I believe your error is caused by Outlook.OlAttachmentType.olByReference . Unfortunately I could not find, on google, any direct connection regarding OlAttachmentType and "an object could not be found" - so you either do the digging yourself or you provide more info.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜