[英]How to get the body of an outlook message
I have some code that send e-mails. 我有一些发送电子邮件的代码。 It creates a default message then allows the user to modify it.
它创建一个默认消息,然后允许用户对其进行修改。 What I would like to do is archive the message that gets sent out but any recipients that may get added.
我想做的是存档已发送的邮件,但可能添加任何收件人。 The problem is when the user clicks send the mail object gets set to null.
问题是当用户单击发送时,邮件对象被设置为null。
Public Shared Function SendRFQ(ByVal strRFQID As String, ByVal strTo As String, ByRef EmailSent As Structs.Email) As Boolean
Dim bRC As Boolean
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
objOutlook = CType(CreateObject("Outlook.Application"), Outlook.Application)
objEmail = CType(objOutlook.CreateItem(Outlook.OlItemType.olMailItem), Outlook.MailItem)
With objEmail
.CC = "Employee@Work.com"
.Subject = String.Format("RFQ")
.To = strTo
.Body = Constants.RFQ.Email.Body
.Display(True)
End With
'objEmail is null
EmailSent.To = objEmail.To
EmailSent.Subject = objEmail.Subject
EmailSent.Body = objEmail.Body
End Function
I get an COM exception; 我收到一个COM异常; "The item has been moved or deleted."
“该项目已被移动或删除。”
Is there any way to accomplish this? 有什么办法可以做到这一点?
You can do this by using the Send
event of the MailItem
. 您可以通过使用
MailItem
的Send
事件来执行此操作。 The following Console app shows how. 以下控制台应用程序显示了操作方法。 You should be able to adapt it to your needs.
您应该能够使其适应您的需求。
Imports Microsoft.Office.Interop
Module Module1
Private WithEvents objEmail As Outlook.MailItem
Sub Main()
Dim objOutlook As Outlook.Application
objOutlook = CType(CreateObject("Outlook.Application"), Outlook.Application)
objEmail = CType(objOutlook.CreateItem(Outlook.OlItemType.olMailItem), Outlook.MailItem)
With objEmail
.CC = "a@b.com"
.Subject = "Subject"
.To = "jc@d.com"
.Body = "Body"
.Display(True)
End With
objOutlook = Nothing
End Sub
Private Sub objEmail_Send(ByRef Cancel As Boolean) Handles objEmail.Send
Console.WriteLine(objEmail.Body)
Console.WriteLine(objEmail.To)
Console.WriteLine(objEmail.Subject)
End Sub
End Module
You just need to keep the values of the contents of the email and populate your ByRef object: 您只需要保留电子邮件内容的值并填充ByRef对象即可:
Dim cc = "Employee@Work.com"
Dim subject = String.Format("RFQ")
Dim body = Constants.RFQ.Email.Body
With objEmail
.CC = cc
.Subject = subject
.To = strTo
.Body = body
.Display(True)
End With
EmailSent.To = strTo
EmailSent.Subject = subject
EmailSent.Body = body
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.