In my code, I'm generating an Email, which is then shown to the user so they can edit it before sending. After they're done with editing, I want to store the edited Email as a File, but I don't know how to access it after it has been sent. The most logical way to go about it seems to be to react to the Send - Event to store it as soon as the user sends it:
Dim oMail As Outlook.MailItem
'Fill oMail
oMail.Display()
AddHandler oMail.Send, AddressOf MailSent
However, the signature for MailSent has to look like this:
Private Sub MailSent(ByRef Cancel As Boolean)
I don't know how I would access the MailItem in MailSent since there's no sender object or anything of the like.
Maybe this isn't supposed to be possible and i'm supposed to read the last item in the Folder "Sent" Instead?
CodePudding user response:
Wrap the MailItem
object into your own class with a constructor that takes MailItem
as a parameter, saves it in a member variable, and sets the event handler. When the event handler fires, you have your class variable to reference.
You can also use Application.ItemSend
event, which does pass the item being sent (could be MailItem
or MeetingRequest
object) as a parameter.