Clear Categories in Outlook 2003 - outlook

Outlook 2007 automatically strips categories from incoming email.
Outlook 2003 does not do this, forcing the recipient to use the senders categories.
Is there a way to either:
Force Outlook 2003 to remove the categories (can't do it via Rules and Alerts) on incoming email.
OR
Force both Outlook 2007 and Outlook 2003 to remove categories before sending?
Thanks,
Jeff

Try setting up a rule to run a script:
Sub RemoveCategories(MyMail As MailItem)
Dim strID As String
Dim objMail As Outlook.MailItem
strID = MyMail.EntryID
Set objMail = Application.Session.GetItemFromID(strID)
objMail.Categories = ""
objMail.Save
Set objMail = Nothing
End Sub
This is based on this article.

Related

How to add custom property to InternetHeaders of Outlook MailItem

I need to add custom InternetHeader x-auth-guid to existing MailItem in Outlook inbox (in Exchange account) from VSTO add-in. Something like described here
https://learn.microsoft.com/en-us/previous-versions/office/developer/exchange-server-2010/dd633654(v=exchg.80)
but without EWS.
The code using EWS work and do something like:
extendedFieldURI.propertyName = "x-auth-guid"
extendedFieldURI.distinguishedPropertySetId = "InternetHeaders"
property.extendedFieldURI = extendedFieldURI
property.value = xauthGuid
message.addExtendedProperty(property)
But in add-in both PropertyAccessor like:
mailItem.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/x-auth-guid", xauthGuid);
mailItem.Save();
and Redemption
rdoMail.Fields["http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/x-auth-guid"] = xauthnGuid;
rdoMail.Save();
seems don't work. Am I missing something?

Sending email through Outlook on Windows 10 using VB6 error: runtime 287 - application-defined or object-defined error

We run an old Visual Basic 6 application on both Windows 7 and Windows 10.
One of the functions is for sending outgoing email through the Outlook desktop client.
The same application that works on Windows 7 machines is not working on Windows 10 PC. No email is sent on Windows 10 PC.
Public Sub SendOlMail(Subject As String, attachment As String, Recipient As String, bodytext As String)
Const olMailItem = 0
Dim objOutl As Object
Dim objMailItem As Object
Set objOutl = CreateObject("Outlook.Application")
Set objMailItem = objOutl.CreateItem(olMailItem)
objMailItem.Recipients.Add Recipient
objMailItem.Subject = Subject
objMailItem.Body = bodytext
objMailItem.Attachments.Add attachment
objMailItem.Send
Set objMailItem = Nothing
Set objOutl = Nothing
End Sub
After removing On Error Resume Next I got the error message on Windows 10 PC.
runtime 287 - application-defined or object-defined error
I found the error is on line objMailItem.Recipients.Add Recipient and looks like something missed in the Windows 10 PC.
Tried to run the app as administrator and still not working.

Outlook OLE Automation: BodyFormat not supported?

I am trying to send an email in Outlook using OLE Automation. At the moment, I am using VBS for testing purposes. When it works, I will switch to another language that supports OLE/COM.
The problem with my code is, that I get error 800a0005 "Invalid procedure call" with argument 'BodyFormat'.
According to the documentation of Microsoft, BodyFormat is existing since Outlook 2003. I am testing with Outlook 2010.
My code:
Set ol = WScript.CreateObject("Outlook.Application")
Set ns = ol.getNamespace("MAPI")
Set newMail = ol.CreateItem(olMailItem)
With newMail
.BodyFormat = olFormatHTML
.HTMLBody = "<HTML><H2>The body of this message will appear in HTML.</H2><BODY>Type the message text here. </BODY></HTML>"
.Display
End With
The background: At the moment, some customers receive emails in TNEF format and can't open the email attachment winmail.dat. So I am trying to force Outlook to use HTML instead of RichText.
What can I do?
Constant olFormatHTML is not defined by default.
Add the following line at the beginning of your VBS code:
Const olFormatHTML = 2

What are the prerequisites for installing CDO.DLL in Windows Server 2012 for VB application

I am upgrading a server from Windows 2003 to 2012 R2.
One of our VB6 applications used CDO.dll for MAPI, i.e. for sending mails.
My question is :
How do I install/register CDO.DLL?
What are the prerequisites for installing CDO.DLL?
Do I need to install Outlook in my server for the application to send mail?
Set objMAPI = New MAPI.Session
objMAPI.Logon ShowDialog:=False, NewSession:=False, ProfileInfo:=gobjINI.gstrExchangeServer & vbLf & gobjINI.gstrProfile
'Add a new mesage to the OUtbo Messages Collection
Set objMSG = objMAPI.Outbox.Messages.Add
'Add the recipient list specified in INI File
'Check if this is a multiple Recipient List (names or groups seperated by semicolons!)
If InStr(1, Recipients, ";") Then
objMSG.Recipients.AddMultiple Recipients, CdoTo
objMSG.Recipients.Resolve
Else
'This section is for handling of single recipient name
'Be aware that this may be an email group list name !
Set objRecipients = objMSG.Recipients.Add(Recipients)
objRecipients.Resolve
End If
'Add Subject Line, Message Content and Send Message
objMSG.Subject = Subject
objMSG.Text = Message
'The Update method adds all our assignments to collecttion
objMSG.Update
'Now let's actually send the message
objMSG.Send
'End MAPI Session
objMAPI.Logoff
Set objMAPI = Nothing
MailSend = True
CDO 1.21 is no longer being developed or supported by Microsoft. You can download the standalone version of MAPI along with CDO 1.21 from https://www.microsoft.com/en-us/download/details.aspx?id=42040. It was last updated in 2014 and no new bug fixes are expected. Functionality wise it has not been updated for the last 15 years.
You can switch to the Outlook Object Model (Namespace object roughly corresponds to the MAPI.Session object).
You can also use Redemption (I am its author) - its RDOSession object is similar to the MAPI.Session object (with a lot more extra features).

Whats the best way to Programmatically Process New Email Messages and Store Attachments

I have several clients/vendors that distribute reports to me via email. Some of these files are enormous, and need to be removed from email and saved on a file share for processing, as well as to control mailbox size.
Can anyone provide guidance on their recommended method of automatically downloading and saving attachments.
I am in a MS Windows Environment (Client & Server Computers). Emails are on an Microsoft Exchange 2003 Email Server.
Preferred use of Microsoft Technology for consistency across solutions (C#), however I am open to any suggestions, be it C#, VBScript, Perl, Java, Components I should purchase, etc..
Scenario
Each Day bob#whysendmereportsbyemail.com sends an email with the subject "Activity Report for YYYY-MM-DD" to me at
john#myemailaddress.com
Each Email has an attachment named "ActivityReport-YYYY-MM-DD-HH-MI-SS.xls" which I need to save on my filesystem at
"C:\FilesFromBob\ActivityReport-YYYY-MM-DD-HH-MI-SS.xls"
Thanks in advance for any assistance.
Exchange 2003 provides a WebDav API which you can use to access emails, contacts etc.. from a user's account.
There's a few answers about accessing a user's Exchange inbox on SO already. I've previously used this approach for almost exactly the situation you outline, and once you work out the WebDav API model and the structure of the requests and responses, it's not too difficult to extract emails and their attachments.
There are other ways to interact with Exchange 2003 (outlined on SO here), but I've only tried the WebDav approach because it seemed the most reliable.
I finally wrote the code to store messages from Outlook
Unfortunately this code runs from within Outlook, so Outlook has to be open.
I did not yet investigate how to schedule the run, but now its easy to do
Sub SaveOutlookFileAttachments()
Dim oStores As Outlook.Stores
Dim oStore As Outlook.Store
Dim oFolders As Outlook.Folders
Dim oFolder As Outlook.Folder
Dim destFolder As String
Dim oItems As Outlook.Items
Dim oMsg As Outlook.MailItem
Dim oAttachments As Outlook.Attachments
Dim oAttachment As Outlook.Attachment
Dim oExplorer As Outlook.Explorer
destFolder = "\\NetworkShare\OrderDetailReport\"
On Error Resume Next
Set oStores = Application.Session.Stores
For Each oStore In oStores
If oStore.DisplayName = "Inbox" Then
oFolders = oStore.GetSearchFolders
For Each oFolder In oFolders
oItems = oFolder.Items
For Each oMsg In oItems
oAttachments = oMsg.Attachments
For Each oAttachment In oAttachments
If InStr(1, oAttachment.FileName, "orderdetail_", vbTextCompare) Then
'MsgBox ("This File Needs to be Saved: " & oAttachment.FileName)
oAttachment.SaveAsFile (destFolder & oAtch.DisplayName)
End If
Next
Next
Next
End If
Next
End Sub

Resources