receive windows popup message or alert for a specific incoming mail - powershell

we have following problem. we need an extra windows popup message or baloon tip message in windows, if a mail from a specific sender arrives in outlook. are there any examples in powershell or any other programms recommend?
thanks in advance

You can use basic Outlook rules to create a desktop alert with any given condition, no need for any script or special program
If you want, the rule can also run a script and then you can do whatever you want there

From the following webpage, https://www.slipstick.com/outlook/rules/outlooks-rules-and-alerts-run-a-script/
Using VBA
Something like this:
Public Sub ShowMessage(Item As Outlook.MailItem)
'code
End Sub
The argument must by type MailItem or MeetingItem for the subroutine to be available in the Rules Wizard in Outlook 2007. In Outlook 2010 and 2013 (and up), PostItem also works.
Open Rules Wizard. In Outlook 2010 and 2013, it's on Outlook's Home ribbon,
Rules > Manage Rules & Alerts. Look on the Tools menu in older versions.
Open Rules Wizard
Click New Rule.
Select Apply Rule on messages I receive and click Next.
Select your conditions and click Next.
Select Run a script action (near the bottom).
The finished run a script rule
Click on a script.
Select the script
Select your script, click OK.
Click Next then finish the rule.

There are several ways to get the job done:
Create a rule in Outlook manually and assign a VBA macro which can be triggered by the rule. For example:
Public Sub TestRule(Item As Object)
If(Item.SenderEmailAddress = "eugene#test.com") Then
MsgBox "Got email!"
End If
End Sub
Use the VBA routine for handling incoming emails. The NewMailEx event fires when a new message arrives in the Inbox and before client rule processing occurs. You can use the Entry ID returned in the EntryIDCollection array to call the NameSpace.GetItemFromID method and process the item. This event fires once for every received item that is processed by Microsoft Outlook. The item can be one of several different item types, for example, MailItem, MeetingItem, or SharingItem. The EntryIDsCollection string contains the Entry ID that corresponds to that item.
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
Dim mai as Object
Set mai = Application.Session.GetItemFromID(EntryIDCollection)
If(mai.SenderEmailAddress = "eugene#test.com") Then
MsgBox "Got email!"
End If
End Sub

Related

Automatically download emails from Outlook with SAS or Outlook rule

I am trying to create a program to automatically download the attached files that are sent to us from a certain email and then transform the delimiter with SAS, of those csv that are attached to us and pass those csv through a flow that I have already created.
I have managed to create a program that treats the csv as I want and the delimiter that I want, the problem is that when it comes to automating the download of files from Outlook it does not work.
What I have done is create a rule with the following VB code that I found on the internet:
Public Sub SaveAttachmentsToDisk(MItem As Outlook.MailItem)
Dim oAttachment As Outlook.Attachment
Dim sSaveFolder As String
sSaveFolder = "C:\Users\ES010246\Desktop"
For Each oAttachment In MItem.Attachments
oAttachment.SaveAsFile sSaveFolder & oAttachment.DisplayName
Next
End Sub
I have changed the path to my personal path where i want the files are downloaded.
website: https://es.extendoffice.com/documents/outlook/3747-outlook
The problem is that this code does not work for me, it does absolutely nothing for me and no matter how much I search the internet, only this code appears.
Is there any other way to do with SAS what I want? What is it to automatically download 8 csv files sent to me by Outlook, or has someone experienced the same thing as me with VBA?
I have followed all the steps about 7 times so I think the error is not in copying the code or selecting certain options wrong, in fact I had copied and pasted the code and later I modified the path where I wanted those to be saved. files but it doesn't work, does anyone know why?
I will be tremendously grateful, thank you very much for everything!
First of all, you need to make sure the file name and path doesn't include forbidden symbols.
The VBA macro used for a rule in Outlook is absolutely valid except that a mail item may contain the attached files with the same name, so a file saved to the disk may be overwritten (saved with the same name). That's why I'd suggest generating a file name with your own unique IDs making sure that DisplayName property is not empty and has a valid name what can be used for file names (exclude forbidden symbols).
Also you may consider handling the NewMailEx event of the Application class which is fired when a new message arrives in the Inbox and before client rule processing occurs. Use the Entry ID returned in the EntryIDCollection string to call the NameSpace.GetItemFromID method and process the item. This event fires once for every received item that is processed by Microsoft Outlook. The item can be one of several different item types, for example, MailItem, MeetingItem, or SharingItem.
The Items.ItemAdd event can be helpful when items are moved to a folder (from Inbox). This event does not run when a large number of items are added to the folder at once.

MailMerge not working on Office 2016

I have one program which uses mailmerge in Word and it works perfectly in office 2007 and tested in 2010. But in office 2016 it throws an error
Code is below
ASSIGN lv_cDocument = fiFile. /* chosen from program select */
ASSIGN lv_cDataFile = "C:\a\data.dat".
ASSIGN lv_cMailMergeFile = "C:\a\dataOutput.doc".
MailMerge(lv_cDocument, /* Main Document */
lv_cDataFile, /* File that holds all the data */
lv_cMailMergeFile, /* File to hold new mail merge document */
NO).
DEFINE VARIABLE oWord AS COM-HANDLE NO-UNDO.
CREATE "Word.Application" oWord.
oWord:Documents:Open("C:\a\dataOutput.doc").
oWord:Visible = True.
RELEASE OBJECT oWord.
Any thoughts what is "new" in new office so i can modify my program that it works on all version of MS-Offices?
When doing COM, both applications (OrenEdge and Word) should be same "bitness". To be safe, both products should be 32 bit - I'm not 100% sure if 64 bit Word supports Automation interfaces.
The alternative on 11.6 might be the Interop API's (.NET): https://msdn.microsoft.com/de-de/library/microsoft.office.interop.word(v=office.11).aspx
The problem was in Word options.
Steps to resolve the auto launch errors:
Open MS Word.
Click on File > Options.
In the General section under Start up options, uncheck the "Open e-mail attachments and other uneditable files in reading view" box.
Close Word and try to export and auto launch your document again. It may take a couple of tried for Word to realize the setting has been changed.
Source
Problem for me was although it shows only ms office 2016 is installed and only one version of it. When I looked under start and went to outlook it showed the normal icon for outlook and the another one that said outlook 2016.
So I set up the user profile on the normal outlook, made sure that is open and not the outlook 2016 one and now the mail merge works for me.
Hope this helps someone out.

Automatically send email about editing google spreadsheet

I'm working on a rather simple script which should handle new values in the spreadsheet and then send emails to specified addresses. And I faced with the problem. My code is listed below:
function onEdit(e) {
//part of the code for checking e.range to process only updated values
sendEmail();
}
function sendEmail() {
// arguments are missed only for demo
GmailApp.sendEmail();
}
While I'm using "simple trigger", my function "sendEmail()" works only if I start it from script editor. I allowed sending emails on behalf of my at first time and then function works fine. But if I'm changing the value in the spreadsheet - function "onEdit(e)" processes new data but function "sendEmail()" does nothing.
I partly solved this problem by using project's triggers from "current project's triggers" menu. In that case, function "sendEmail()" works properly, but I have no access to the information about update.
For my purposes I could use just second way and find new values "manually" every time, but I wish to optimize this work.
So, my questions are:
Is the process I described above proper or I made a mistake
anywhere?
If process proper, is where a way to combine both cases?
Thanks!
You correctly understood that (as the docs say) simple triggers cannot send an email, because they run without authorization. An installable trigger, created via Resources menu, can: it has the same rights as the user who created the trigger. If it is set to fire on edit, it will get the same type of event object as a simple trigger does.
So, a minimal example would be like this, set to run "on edit":
function sendMail(e) {
MailApp.sendEmail('user#gmail.com', 'sheet edited', JSON.stringify(e));
}
It emails the whole event object in JSON format.
Aside: if your script only needs to send email but not read it, use MailApp instead of GmailApp to keep the scope of permissions more narrow.

VSTO Word add-in - new document event not firing if Word is launched from the executable

In my add-in, I need to create a task pane for each open document. In the add-in's startup method, I subscribe to the ApplicationEvents4_Event.NewDocument and Application.DocumentOpen events, and then create a task pane for each opened document:
((ApplicationEvents4_Event)Application).NewDocument += CreateTaskPaneWrapper;
Application.DocumentOpen += CreateTaskPaneWrapper;
foreach (Document document in Application.Documents)
{
CreateTaskPaneWrapper(document);
}
This covers cases for opening or creating a document through Word's menu, or opening an existing document file in the OS. However, if Word is already opened, launching WINWORD.EXE (or accessing it through a shortcut, which is a pretty common scenario) doesn't trigger either event, despite a new window with a new document being opened. How can I react to this scenario and create a task pane for a document created this way? I'm using VSTO 3 and Visual Studio 2008, targeting Word 2007.
If Word is started, a new document is created BEFORE the Add-In loads, therefore this event can not be trapped.
If you need to work with the initially created document, just take a look at the Documents collection - if Count is greater zero, this document is the one created by Word before your Add-In was loaded.
So I solved this problem in my solution, although I'm not sure it will be cross applicable. Sadly, mine is in VB.Net, so there may need to be some translation.
First, I ended up not using ApplicationEvents4_Event Instead there are other built in event triggers you can use via "ThisAddIn"
Private Sub Application_NewDocument(ByVal Doc As Word.Document) Handles Application.NewDocument
'MsgBox("I opened something")
myCustomTaskPane = Me.CustomTaskPanes.Add(New MyCustomTaskPaneClass, "TaskPane", Doc.ActiveWindow)
myCustomTaskPane.Visible = True
End Sub
Using this method I did have a similar challenge. Running winword.exe, and thereby opening a new word document, did not trigger the NewDocument event. Luckily, there was another event to use - Document change.
Private Sub Application_DocumentChange() Handles Application.DocumentChange
'function to test if the ActiveDocument has a taskpane from my add-in, and then a function to add one
If Not HasMyCustomTaskPane() then AddCustomTaskPane()
End Sub
So - bottom line, regardless of if you keep using ApplicationEvents4_Event you should see if you can use the DocumentChange event. It triggers when a new word window is selected.
Handling task panes for more than one window in Word is fairly complicated, because of how Word loads and re-uses open windows. To do it correctly, you have to consider different actions:
The user takes an action to display or hide a task pane.
The user creates a new document.
The user opens an existing document.
The user closes an open document.
There's a tutorial that explores all the details, both in VB and C#: https://msdn.microsoft.com/en-us/library/bb264456%28v=office.12%29.aspx
I also found a similar answer on SO.

Displaying Data in the Outlook Toolbar via VBA

Okay, at my work, our procedures/guidelines require us to send emails letting other employees know if we are leaving our desk for extended periods of time. It's an empty email body (apart from our signature), and the subject says IN, OUT, or 10.
I've gotten into the habit of simply deleting these emails as they come, to reduce clutter. But it's difficult to keep track of who is in or out. So I would like to write an add-in that will show who is in or out based on these emails. My idea at the moment, is to create labels in the toolbar with each employee's name, and whether they are in or out.
Can anybody suggest a good way to go about doing this?
You could create an addin for this (using VB6, or VSTO), or use some VBA to process incoming emails and create calendar appointments to block out the time those folks are AFK.
Something like:
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
If TypeName(item) = "MailItem" Then
Set Msg = item
If Msg.Subject = "OUT" Then
' create calendar appointment here
End If
If Msg.Subject = "IN" Then
' delete calendar appoinment here
End If
End If
ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ProgramExit
End Sub
I recommend an alternative: use the Out of Office feature. I realize the subject line will say "Out Of Office" even if you are only using the bathroom or at a meeting, but I can't imagine it's worse than what you are doing now. It's built-in and doesn't require so much effort.
ps- This is none of my business and I'll probably get flamed for asking this, but could you tell us what company that is, so I know never to work there? It sounds absolutely horrible.
You should signup for the MS BizSpark and download Lync Server/Communicator. It has built-in presence awareness - something you are better off investing your efforts into than this strange Outlook VBA/email setup.
As an alternative, you can also get jabber clients free if you want to go the jabber route. jabber.org offers free accounts if you don't want to host your own jabber server.
Both these approaches are a standards-based way of knowing peoples availability (presence) without having to rely on them to perform any manual actions.