Hi,
I made the stupid error or paying a freelancer to write some code that would convert emails received from certain email address and convert them to plain txt from html and forward onto another email.
Here is the code, I am not sure how to execute this because I want it to only work on emails in certain folder (TEST) and only on unread ones then mark them read or something after forwarding so i can leave it running constantly and so it doesn't loop and send the same email twice.
Thankyou.
I made the stupid error or paying a freelancer to write some code that would convert emails received from certain email address and convert them to plain txt from html and forward onto another email.
Here is the code, I am not sure how to execute this because I want it to only work on emails in certain folder (TEST) and only on unread ones then mark them read or something after forwarding so i can leave it running constantly and so it doesn't loop and send the same email twice.
Code:
Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Dim olApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Set olApp = Outlook.Application
Set objNS = olApp.GetNamespace("MAPI")
Set Items = objNS.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub Items_ItemAdd(ByVal Item As Object)
On Error GoTo ErrorHandler
Dim Msg As Outlook.MailItem
Dim MBody As String
If TypeName(Item) = "MailItem" Then
Set Msg = Item
If Msg.SenderName = "Andrew Smith" Or Msg.SenderEmailAddress = "Andrew.Smith@azzu.co.uk" Then
MBody = HtmlToText(Msg.HTMLBody)
Dim objMsg As MailItem
Set objMsg = Application.CreateItem(olMailItem)
objMsg.Body = MBody
objMsg.Subject = "FW: " & Item.Subject
objMsg.Recipients.Add "andrew.smith@azzu.co.uk"
objMsg.Send
End If
End If
ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ProgramExit
End Sub
Function HtmlToText(sHTML) As String
Dim oDoc As HTMLDocument
Set oDoc = New HTMLDocument
oDoc.Body.innerHTML = sHTML
HtmlToText = oDoc.Body.innerText
End Function
Thankyou.