Is there any possibility to access the automatic answering function of Outlook out of my humble WinFormsApp (C#)? To activate it directly out of my App for the time of vacations e.g.
Really appreciate any ideas!
That's what i have but C# doesn't accept the last line:
private void Btn_Click(object sender, EventArgs e)
{
var OLApp = new Outlook.Application();
object OLAssistent = OLApp.AnswerWizard();
}
First of all, the AnswerWizard property is deprecated. Here is what MSDN documentation states:
This object, member, or enumeration is deprecated and is not intended to be used in your code.
Instead, you may consider using EWS if you deal with Exchange accounts or Graph API in case of Office365 accounts configured in Outlook.
Related
I am performing custom action on all incoming replies through VSTO add-in. The add-in will compare ConversationID of incoming reply with existing email. It works fine if I have to search inside one folder but my problem is email can be in any folder in store. Here is my code.
void items_ItemAdd(object Item)
{
Outlook.Application application = new Outlook.Application();
string filter = "RE: ";
Outlook.MailItem mail = (Outlook.MailItem)Item;
Outlook.Folder folder = mail.Parent as Outlook.Folder;
if (Item != null)
{
if (mail.MessageClass == "IPM.Note" && mail.Subject.ToUpper().Contains(filter.ToUpper()))
{
var RequiredMail = (from e in folder.Items.Cast<Outlook.MailItem>().OrderBy(X => X.ReceivedTime).Where(C => C.ConversationID == mail.ConversationID) select mail).FirstOrDefault();
// Perform custom action
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
Also, I have read that searching for an email using Linq is not very efficient. Is there any other more efficient way to get RequiredMail?
Any help will be highly appreciated.
Thank you.
First of all, you must be aware that ItemAdd event may not be fired if more than sixteen items are added to the collection. This is a known issue in Outlook. The following series of articles describes possible workarounds for that:
Outlook NewMail event unleashed: the challenge (NewMail, NewMailEx, ItemAdd)
Outlook NewMail event: solution options
Outlook NewMail event and Extended MAPI: C# example
Outlook NewMail unleashed: writing a working solution (C# example)
Mixing LINQ and COM objects is not a really good idea. You should release underlying COM objects instantly to prevent any known issues.
If you need to search for items in all folders you may use the AdvancedSearch method of the Application class which allows to perform a search based on a specified DAV Searching and Locating (DASL) search string.
The key benefits of using the AdvancedSearch method in Outlook are:
The search is performed in another thread. You don’t need to run another thread manually since the AdvancedSearch method runs it automatically in the background.
Possibility to search for any item types: mail, appointment, calendar, notes etc. in any location, i.e. beyond the scope of a certain folder. The Restrict and Find/FindNext methods can be applied to a particular Items collection (see the Items property of the Folder class in Outlook).
Full support for DASL queries (custom properties can be used for searching too). You can read more about this in the Filtering article in MSDN. To improve the search performance, Instant Search keywords can be used if Instant Search is enabled for the store (see the IsInstantSearchEnabled property of the Store class).
You can stop the search process at any moment using the Stop method of the Search class.
Read more about that in the Advanced search in Outlook programmatically: C#, VB.NET article.
Last night I wanted to start a new project, but with a strange Error I face !!!
If anyone has worked with Translation API, please help!
The Error Tip is :
The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.
and My Codes are Here too.
private void Form1_Load(object sender, EventArgs e)
{
TranslationClient cli = TranslationClient.Create();
var word = cli.TranslateText("hello","fa");
MessageBox.Show(word.TranslatedText.ToString());
}
I am working on a Windows Phone 8 app and am trying to share content through the DataTransferManager. The Windows API documentation says it is supported in Windows Phone but when the DataTransferManager.GetForCurrentView() function is called I get an exception
System.NotSupportedException was unhandled by user code
HResult=-2146233067
Message=Specified method is not supported.
Source=Windows
InnerException:
I have been searching for an answer and can't find anyone else with the same issue, any help would be appreciated. All samples on this topic seem to be Windows 8 specific, but Phone 8 does include these functions. Here's sample code from my app.
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
dataTransferManager.DataRequested += new TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(dataTransferManager_DataRequested);
}
private void dataTransferManager_DataRequested(DataTransferManager sender, DataRequestedEventArgs e)
{
DataPackage requestData = e.Request.Data;
requestData.Properties.Title = "Share Text Example";
requestData.Properties.Description = "An example of how to share text.";
requestData.SetText("Hello World!");
}
private void Button_Tap_1(object sender, System.Windows.Input.GestureEventArgs e)
{
DataTransferManager.ShowShareUI();
}
Again, the exception is shown when the page loads on the DataTransferManager.GetForCurrentView(); function so it doesn't get to the other lines, but included them anyway. I've tried adding/removing permissions and assemblies but must be missing something. I've also tried putting the function in different events (such as the onTap function) with the same results.
If anyone is interested in trying this on their own here is some documentation:
DataTransferManager
DataRequested
DataPackage
GetForCurrentView()
UPDATE
Although it may not be the best solution given the context of this question, I am implementing the Email/Sms/Link Tasks as described below rather than using the DataTransferManager. It seems that DataTransferManager may not be accessible in WP8 and although the tasks will take a number of different functions they seem to be the best way to perform the intended functionality.
I think I have found most of what I was looking for with Launchers... Rather than just using the Windows 8 general sharing functionality I can be specific with Tasks/Launchers.
Unfortunately it doesn't have as many sharing options as the charm does, I will be implementing several functions for email/sms/social but so far this is the best solution.
Here are the functions that I will be implementing
private void ShareLink(object sender, System.Windows.Input.GestureEventArgs e)
{
ShareLinkTask shareLinkTask = new ShareLinkTask()
{
Title = "Code Samples",
LinkUri = new Uri("http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff431744(v=vs.92).aspx", UriKind.Absolute),
Message = "Here are some great code samples for Windows Phone."
};
shareLinkTask.Show();
}
private void ShareEmail(object sender, System.Windows.Input.GestureEventArgs e)
{
EmailComposeTask emailComposeTask = new EmailComposeTask()
{
Subject = "message subject",
Body = "message body",
To = "recipient#example.com",
Cc = "cc#example.com",
Bcc = "bcc#example.com"
};
emailComposeTask.Show();
}
private void ShareSMS(object sender, System.Windows.Input.GestureEventArgs e)
{
SmsComposeTask smsComposeTask = new SmsComposeTask()
{
Body = "Try this new application. It's great!"
};
smsComposeTask.Show();
}
Ref:
Launchers for Windows Phone
Share Link Task
According to my API reference, DataTransferManager is reserved for native apps only. Windows Phone API Quickstart.
Have you tried using the fully qualified method? It would be something like this:
DataTransferManager dataTransferManager = indows.ApplicationModel.DataTransfer.DataTransferManager.getForCurrentView();
Also, make sure your target is Windows Phone 8.
The Windows 8 Share Contract isn't supported on WP8. There isn't even a Share charm on WP8. Why are you trying to use the DataTransferManager?
Instead of using the Share Contract, most usecases can work just fine with WP8 app2app custom protocols and file extensions. Using WP8 app you can transfer files and data across apps. Althrough the standardized contract of the Share Contract is gone, apps can create their own contracts using custom protocols and file extensions.
Here for example you can learn more about a real-world 3rd party implementation of Nokia Music custom protocols.
When using a simple command line svn client, if you run update you can see the changes that were made to your working copy.
I've been trying to do so in SharpSvn (with C#, .Net 3.5), because I need to see if the Client.Update() operation caused deletion of files, for example.
I tried using SvnUpdateResult, but it returns one item, for the entire folder, with no details I can find. I also can't find anything that looks useful in SvnUpdateArgs.
Help please?
Thanks.
You can subscribe to the Notify event, on SvnUpdateArgs or on the client instance itself:
SvnUpdateArgs ua = new SvnUpdateArgs();
ua.Notify += delegate(object sender, SvnNotifyEventArgs e)
{
Console.Write(e.Action);
Console.WriteLine(e.FullPath);
};
I'm working on a windows client written in WPF with C# on .Net 3.5 Sp1, where a requirement is that data from emails received by clients can be stored in the database. Right now the easiest way to handle this is to copy and paste the text, subject, contact information and time received manually using an arthritis-inducing amount of ctrl-c/ctrl-v.
I thought that a simple way to handle this would be to allow the user to drag one or more emails from Outlook (they are all using Outlook 2007 currently) into the window, allowing my app to extract the necessary information and send it to the backend system for storage.
However, a few hours googling for information on this seem to indicate a shocking lack of information about this seemingly basic task. I would think that something like this would be useful in a lot of different settings, but all I've been able to find so far have been half-baked non-solutions.
Does anyone have any advice on how to do this? Since I am just going to read the mails and not send anything out or do anything evil, it would be nice with a solution that didn't involve the hated security pop ups, but anything beats not being able to do it at all.
Basically, if I could get a list of all the mail items that were selected, dragged and dropped from Outlook, I will be able to handle the rest myself!
Thanks!
Rune
I found a great article that should do exactly what you need to.
UPDATE
I was able to get the code in that article working in WPF with a little tweaking, below are the changes you need to make.
Change all references from System.Windows.Forms.IDataObject to System.Windows.IDataObject
In the OutlookDataObject constructor, change
FieldInfo innerDataField = this.underlyingDataObject.GetType().GetField("innerData", BindingFlags.NonPublic | BindingFlags.Instance);
To
FieldInfo innerDataField = this.underlyingDataObject.GetType().GetField("_innerData", BindingFlags.NonPublic | BindingFlags.Instance);
Change all DataFormats.GetFormat calls to DataFormats.GetDataFormat
Change the SetData implementation from
public void SetData(string format, bool autoConvert, object data)
{
this.underlyingDataObject.SetData(format, autoConvert, data);
}
TO
public void SetData(string format, object data, bool autoConvert)
{
this.underlyingDataObject.SetData(format, data, autoConvert);
}
With those changes, I was able to get it to save the messages to files as the article did. Sorry for the formatting, but numbered/bulleted lists don't work well with code snippets.
I found a lot of solutions suggesting you use the “FileGroupDescriptor” for all the file names and the “FileContents” on the DragEventArgs object to retrieve the data of each file. The “FileGroupDescriptor” works fine for the email message names, but “FileContents” returns a null because the implementation of the IDataObject in .Net cannot handle the IStorage object that is returned by COM.
David Ewen has a great explanation, excellent sample and code download that works great at http://www.codeproject.com/KB/office/outlook_drag_drop_in_cs.aspx.
In your Xaml you need to set up your Event:
<TextBlock
Name="myTextBlock"
Text="Drag something into here"
AllowDrop="True"
DragDrop.Drop="myTextBlock_Drop"
/>
Once you have Set AllowDrop = True and Set you drop event then go to the code behind and set up your event:
private void myTextBlock_Drop(object sender, DragEventArgs e)
{
// Mark the event as handled, so TextBox's native Drop handler is not called.
e.Handled = true;
Stream sr;
//Explorer
if (e.Data.GetDataPresent(DataFormats.FileDrop, true))
//Do somthing
//Email Message Subject
if (e.Data.GetDataPresent("FileGroupDescriptor"))
{
sr = e.Data.GetData("FileGroupDescriptor") as Stream;
StreamReader sr = new StreamReader(sr2);//new StreamReader(strPath, Encoding.Default);
//Message Subject
string strFullString = sr.ReadToEnd();
}
}
If you wish to break it down further you can use:
FILEDESCRIPTOR or FILECONTENTS as outline in the following article
your other option is to tie into outlooks MS Office Primary Interop Assemblies and break the message apart that way.
I think Shell Style Drag and Drop in .NET (WPF and WinForms) can help you. Once you can respond to drag drop using the COM Interfaces, you should be able to get the data out of outlook.
I assume that you have an Exchange server running behind Outlook.
What you can do is to retrieve the mail from the Exchange server and store its location in your database based on the mail's EntryID and StoreID. Here's a VB.Net snippet:
Imports Microsoft.Office.Interop
Public Class OutlookClientHandler
Private _application As Outlook.Application
Private _namespace As Outlook.NameSpace
Public Sub New()
If Process.GetProcessesByName("outlook".ToLower).Length > 0 Then
_application = New Outlook.Application
Else
Dim startInfo As ProcessStartInfo = New ProcessStartInfo("outlook.exe")
startInfo.WindowStyle = ProcessWindowStyle.Minimized
Process.Start(startInfo)
_application = New Outlook.Application
End If
End Sub
' Retrieves the specified e-mail from Outlook/Exchange via the MAPI
Public Function GetMailItem(ByVal entryID as String, ByVal storeID as String) As Outlook.MailItem
_namespace = _application.GetNamespace("MAPI")
Dim item As Outlook.MailItem
Try
item = _namespace.GetItemFromID(entryID, storeID)
Catch comex As COMException
item = Nothing ' Fugly, e-mail wasn't found!
End Try
Return item
End Function
End Class
I guess you are comfortable with using the MAPI, otherwise you can read up here:
http://msdn.microsoft.com/en-us/library/cc765775(v=office.12).aspx
To retrieve the selected e-mails from outlook:
Public Function GetSelectedItems() As List(Of Object)
Dim items As List(Of Object) = New List(Of Object)
For Each item As Object In _application.ActiveExplorer().Selection
items.Add(item)
Next
Return items
End Function
After you've retrieved the e-mails from Outlook you can just push them into your database! Save their EntryID and StoreID (you might want to store their parent's (the folder's) EntryID and StoreID as well).