How to send a mail using Microsoft.Office.Interop.Outlook.MailItem by specifying the From Address

You are using outlook to send the mail. Since outlook must be configured to use the from address of your mail, you cannot provide the from address directly. However, you can select an account available on outlook. For example : using Outlook = Microsoft.Office.Interop.Outlook; Outlook.Accounts accounts = olkApp1.Session.Accounts; foreach (Outlook.Account account in accounts) { // … Read more

Iterate all email items in a specific Outlook folder

In my case the following worked: Sub ListMailsInFolder() Dim objNS As Outlook.NameSpace Dim objFolder As Outlook.MAPIFolder Set objNS = GetNamespace(“MAPI”) Set objFolder = objNS.Folders.GetFirst ‘ folders of your current account Set objFolder = objFolder.Folders(“Foldername”).Folders(“Subfoldername”) For Each Item In objFolder.Items If TypeName(Item) = “MailItem” Then ‘ … do stuff here … Debug.Print Item.ConversationTopic End If Next … Read more

.NET: Get all Outlook calendar items

I’ve studied the docs and this is my result: I’ve put a time limit of one month hard-coded, but this is just an example. public void GetAllCalendarItems() { Microsoft.Office.Interop.Outlook.Application oApp = null; Microsoft.Office.Interop.Outlook.NameSpace mapiNamespace = null; Microsoft.Office.Interop.Outlook.MAPIFolder CalendarFolder = null; Microsoft.Office.Interop.Outlook.Items outlookCalendarItems = null; oApp = new Microsoft.Office.Interop.Outlook.Application(); mapiNamespace = oApp.GetNamespace(“MAPI”); ; CalendarFolder = mapiNamespace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar); … Read more

How to add an embedded image to an HTML message in Outlook 2010

Found the answer here. The key bits being: Const PR_ATTACH_MIME_TAG = “http://schemas.microsoft.com/mapi/proptag/0x370E001E” Const PR_ATTACH_CONTENT_ID = “http://schemas.microsoft.com/mapi/proptag/0x3712001E” Const PR_ATTACHMENT_HIDDEN = “http://schemas.microsoft.com/mapi/proptag/0x7FFE000B” … Set colAttach = l_Msg.Attachments For x = 1 To Items.Count Set l_Attach = colAttach.Add(Items.Item(x)) Set oPA = l_Attach.PropertyAccessor oPA.SetProperty PR_ATTACH_MIME_TAG, ItemTypes.Item(x) oPA.SetProperty PR_ATTACH_CONTENT_ID, “item” & x oPA.SetProperty PR_ATTACHMENT_HIDDEN, True Next

Switching the FROM Inbox

Try this function Function GetAccountOf(sEmailAddress As String, ByRef OLook As Object) As Object Dim oAccount As Object Set GetAccountOf = Nothing For Each oAccount In OLook.Session.Accounts If oAccount = sEmailAddress Then Set GetAccountOf = oAccount Exit Function End If Next oAccount End Function You can then replace the .From line with: .SendUsingAccount = GetAccountOf(“[email protected]”, OLook) … Read more

Search structured text in Outlook body

finalSubj = ParseTextLinePair(initialBod, “Mailbox:”) See “Listing 17.1. Extract data from a structured text block”. https://learn.microsoft.com/en-us/previous-versions/office/developer/office-2007/dd492012(v=office.12) Function ParseTextLinePair(strSource As String, strLabel As String) Dim intLocLabel As Integer Dim intLocCRLF As Integer Dim intLenLabel As Integer Dim strText As String ‘ locate the label in the source text intLocLabel = InStr(strSource, strLabel) intLenLabel = Len(strLabel) If intLocLabel … Read more