我有一些发送电子邮件的代码。它会创建一个默认消息,然后允许用户修改它。我想要做的是归档发送的消息,但可以添加任何收件人。问题是当用户点击发送时,邮件对象被设置为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
我得到一个COM异常; “该项目已被移动或删除。”
有没有办法实现这个目标?
答案 0 :(得分:1)
您可以使用Send
的{{1}} event来完成此操作。以下控制台应用程序显示如何。您应该能够根据自己的需要进行调整。
MailItem
答案 1 :(得分:0)
您只需要保留电子邮件内容的值并填充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