Search for Email, then send as an attachment to another email

C

Crossh

Using VBA, is it possible to attach an email it to another email that is
about to be sent out? The code below finds the email (and works). I also have
code written to create the email to send out (which also works). How do I
tell the code that sends which email to use as the attachment?

Public Sub LookForEmail(strCompany as string, strReqID As String)
Dim objOL As New Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objInbox As Outlook.MAPIFolder
Dim objCompFolder As Outlook.MAPIFolder
Dim objMail As Outlook.MailItem
Set objNS = objOL.GetNamespace("MAPI")
Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
Set objCompFolder = objInbox.Folders(strCompany )
' Search through folders for most recent email containing request id
For Each objMail In objCompFolder.Items
If InStr(1, objMail.Subject, strReqID & " - ") > 0 Then
' this is the one to attach
End If
Next objMail
End Sub

Public Sub SendSafeMail(strTo, strSubject, strBody, Optional strAttachPath)
Dim sMailItem, oItem, Attach
Set sMailItem = CreateObject("Redemption.SafeMailItem")Set oItem =
Outlook.CreateItem(0)
With sMailItem
.Item = oItem 'set Item property
.To = strTo
If Not IsMissing(strAttachPath) Then
.Attachments.Add (strAttachPath)
End If
.HTMLBody = strBody
.Importance = olImportanceHigh
.Subject = strSubject
.Recipients.ResolveAll
.Send
End With
End Sub

Thanks for your help.
 
A

Alan Moseley

As far as I am aware you can use a MailItem object as an attachment using the
Outlook object model, but not so sure about with Redemption. Can you maybe
save the MailItem to a temporary MSG file, then attach the MSG file? i.e.
replace the line:-

'this is the one to attach

with:-

objMail.SaveAs "C:\temp.msg"

then obviously call your SendSafeMail procedure using C:\temp.msg as your
attachment path.
 
K

Ken Slovak - [MVP - Outlook]

If you have an RDOMail object and a reference to another RDOMail object you
can attach the second reference to the first one as an attachment using the
RDOMail.Attachments.Add method. Just pass the reference to the RDOMail
object as the Source argument to the Add method. There's no need to save the
object out to the file system as an MSG file.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top