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.
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.