Way to mimic an Outlook application object with Outlook web - c#

I have a desktop application that launches an outlook client instance with information pre-filled.
var application = new Outlook.Application();
var mItem = (Outlook.MailItem)outLook.CreateItem(Outlook.OlItemType.olMailItem);
mItem.To = "david#emailaddress.com";
mItem.Subject = "Hello";
mItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
mItem.HTMLBody = "Email body";
mItem.Display(false);
This way, the user can make changes before clicking Send in Outlook.
My goal is to mimic this in a webform. Instead of launching desktop Oulook which can't/shouldn't happen due to security concerns, I would like to launch an Outlook Web window instead with information prefilled.

It isn't possible to do, but looks like the only solution is to use EWS Managed API, EWS, and web services in Exchange.

Related

Creating Task for Different Users Outlook account

I have read several posts and got a solution that use Microsoft.Office.Interop.Outlook to work to create a task in Outlook. Here is the code that will create a task in outlook for my user.
public void CreateOutlookTask()
{
Application outlookApp = new Application();
TaskItem oTask = outlookApp.CreateItem(OlItemType.olTaskItem);
Inspector oInspector = oTask.GetInspector;
oTask.Subject = "This is my task subject";
oTask.DueDate = Convert.ToDateTime("06/25/2011");
oTask.StartDate = Convert.ToDateTime("06/20/2011");
oTask.ReminderSet = true;
oTask.ReminderTime = Convert.ToDateTime("06/28/2006 02:40:00 PM");
oTask.Body = "This is the task body";
oTask.Status =OlTaskStatus.olTaskInProgress;
oTask.Save();
}
I still have two issues with the above code.
1) It will only create tasks for the user that is running the application. I hope to create tasks from a web app, so I need to be able to log into each users account because the web app will not have an outlook account.
2) Using Microsoft.Office.Interop.Outlook requires that outlook is installed. I would really like a solution that doesn't require outlook to be installed on the machine, but haven't found one.
Any help on the above two issues would be greatly appreciated.
You can use exchange web services to create items such as this without the need of the interop libraries.
Get started with EWS client applications
If using OOM is still an option, you can use Application.Session.GetSharedDefaultFolder to retrieve the default Tasks folder of another Exchange user. You can then create a new task there using MAPIFolder.Items.Add.

How do you change the sender of Outlook messages?

I've been successfully sending out appointment invites with outlook through c# in an asp.net application. I'm using the following code:
//send out the outlook notification
Outlook.Application outlookApp = new Outlook.Application();
Outlook.AppointmentItem newMeeting = outlookApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem) as Outlook.AppointmentItem;
if (newMeeting != null)
{
newMeeting.MeetingStatus = Microsoft.Office.Interop.Outlook.OlMeetingStatus.olMeeting;
newMeeting.Location = "TBD";
newMeeting.Subject = "New SEB Consult";
newMeeting.Body = "A new meeting has been scheduled. If you're a member of the team, please accept";
newMeeting.Start = meetingDate;
newMeeting.Duration = 60;
Outlook.Recipient recipient = newMeeting.Recipients.Add("Smith John");
recipient.Type = (int)Outlook.OlMeetingRecipientType.olRequired;
((Outlook._AppointmentItem)newMeeting).Send();
}
This works, but my problem is that it's sending them from my email which I'm logged into with outlook on the same computer. I'd like to send them from a different email, so that they appear more like system notifications coming from my application rather than a personal email. I do have the username and password for the account, but the application is eventually going to be run on a remote server, so I can't just log into outlook with another email. Nothing I've been able to find changes the sender. Does anyone have any more information on how to change these credentials, or where it looks for the credentials?
You can't use OLE if you would like to control the emails. OLE is just to control the local outlook instance which is tied to the running account.
You must use the exchange API instead. With it you can create an appointment like described in this MSDN article: How to: Create appointments and meetings by using EWS in Exchange 2013
Appointment appointment = new Appointment(service);
// Set the properties on the appointment object to create the appointment.
appointment.Subject = "Tennis lesson";
appointment.Body = "Focus on backhand this week.";
appointment.Start = DateTime.Now.AddDays(2);
appointment.End = appointment.Start.AddHours(1);
appointment.Location = "Tennis club";
appointment.ReminderDueBy = DateTime.Now;
// Save the appointment to your calendar.
appointment.Save(SendInvitationsMode.SendToNone);
// Verify that the appointment was created by using the appointment's item ID.
Item item = Item.Bind(service, appointment.Id, new PropertySet(ItemSchema.Subject));
Console.WriteLine("\nAppointment created: " + item.Subject + "\n");
The library is open source and available at github.
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution. Read more about that in the Considerations for server-side Automation of Office article.
You may consider using the EWS Managed API, EWS, and web services in Exchange instead.

application to manage multiple outlook accounts

I have multiple outlook accounts, and all accounts are added to the outlook express.
I can list emails from inbox in asp.net application from one account only which is set as default.
I can list emails from another account by setting it as default data file..
here is my code :
public static Microsoft.Office.Interop.Outlook.Items GetHotMailInBoxItemsUsingLoggedInOutLookAccount(this string strMailStatus)
{
Microsoft.Office.Interop.Outlook.NameSpace _ns;
Microsoft.Office.Interop.Outlook.MAPIFolder inboxFolder = null;
Microsoft.Office.Interop.Outlook.Items _items = null;
Microsoft.Office.Interop.Outlook.Application _application = new Microsoft.Office.Interop.Outlook.Application();
_ns = _application.Session;
inboxFolder = _ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
if (strMailStatus.Equals("1"))
{
_items = inboxFolder.Items;
}
else
{
_items = strMailStatus.Equals("2") ? inboxFolder.Items.Restrict("[Unread] = true") : inboxFolder.Items.Restrict("[Unread] = false");
}
_items.Sort("ReceivedTime", true);
return _items;
}
I want to switch "_application.Session" as i want.
ie: change the default data file from asp.net application..
Consider using EWS (Exchange Web Services) instead. See EWS Managed API, EWS, and web services in Exchange for more information.
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.
Read more about that in the Considerations for server-side Automation of Office article.

How to open Outlook new mail window on server C#

I am using this link for open outlook new mail window.
How to open Outlook new mail window c#
But It is working fine On Local machine but when I deployed it on server it shows below error.
Retrieving the COM class factory for component with CLSID
{0006F03A-0000-0000-C000-000000000046} failed due to the following
error: 80040154 Class not registered (Exception from HRESULT:
0x80040154 (REGDB_E_CLASSNOTREG)).
Microoft office outlook is install on local machine not on server.It is required to install and configure outlook on server.
Plz help.
Thanks.
1. Using Outlook
To send an email using outlook, we need to add a reference to the dynamic link library for Outlook which is called Microsoft.Office.Interop.Outlook.dll
For the same follow the below steps:
Go to your solution explorer
Click on add a reference
Click on .Net Tab
Go through the DLL and select Microsoft.Office.Interop.Outlook.dll
correctly.
when you have selected the correct reference you select the “OK” button and this reference will be added to your project under references.
using Outlook = Microsoft.Office.Interop.Outlook;
//method to send email to outlook
public void sendEMailThroughOUTLOOK()
{
try
{
// Create the Outlook application.
Outlook.Application oApp = new Outlook.Application();
// Create a new mail item.
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
// Set HTMLBody.
//add the body of the email
oMsg.HTMLBody = "Hello, Jawed your message body will go here!!";
//Add an attachment.
String sDisplayName = "MyAttachment";
int iPosition = (int)oMsg.Body.Length + 1;
int iAttachType = (int)Outlook.OlAttachmentType.olByValue;
//now attached the file
Outlook.Attachment oAttach = oMsg.Attachments.Add(#"C:\\fileName.jpg", iAttachType, iPosition, sDisplayName);
//Subject line
oMsg.Subject = "Your Subject will go here.";
// Add a recipient.
Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
// Change the recipient in the next line if necessary.
Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add("jawed.ace#gmail.com");
oRecip.Resolve();
// Send.
oMsg.Send();
// Clean up.
oRecip = null;
oRecips = null;
oMsg = null;
oApp = null;
}//end of try block
catch (Exception ex)
{
}//end of catch
}//end of Email Method
For more information Open outlook
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.
Read more about that in the Considerations for server-side Automation of Office article.
Consider using standard .Net classes or any other components designed for the server-side execution. In case of Exchange Server account you can use EWS (Exchange Web Services), see EWS Managed API, EWS, and web services in Exchange .
If you run that code on the server, who will see the newly created message? Even if there is a user logged in locally to the server, IIS runs without a desktop session.
If you want the message to be displayed on the client, that is where your code needs to run. Why not use a mailto url? It will work in any browser and the default email client will be opened. If you need something more sophisticated than that, you need to write your code in JavaScript and create an instance of the Outlook.Application object using new ActiveXObject(). You can only do that in IE and your site must be trusted to do that.

How do I send an email from a WinRT/Windows Store application?

I am developing a Windows Store Application (Windows 8).
I have a need to send emails based on data and address stored in the application data and without the need of the user to type it the data or the address.
What would be the right/easy way to implement it?
EitanB
You can try with
var mailto = new Uri("mailto:?to=recipient#example.com&subject=The subject of an email&body=Hello from a Windows 8 Metro app.");
await Windows.System.Launcher.LaunchUriAsync(mailto);
The correct way would be to use Sharing. Your app should create an HTML document or Text and share it. The user would select Mail from the Share charm and the HTML/Text would become the body of the email.
See here for more info...
http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh973055.aspx
This is the correct syntax to use for a mailto: link (unlike the other examples above with a mailto: which are incorrect..)
var mailto = new Uri("mailto:yourname#email.com?subject=" + subject + "&body=" + body);
await Launcher.LaunchUriAsync(mailto);
The problem with the mailto: method is if the user has no client program associated with mailto: nothing will happen.
The most reliable method to use is a web service or WCF service of some sort. Using the Share Charm while considered the 'correct' way on Windows 8, is not neccessarily the best as the user may still have no email client installed, for example if they rely on gmail.com for their email.
If you are developping a Universal WinRT Windows Phone application, you could use the "Windows.ApplicationModel.Email.EmailMessage" namespace as the "Microsoft.Phone.Tasks.EmailComposeTask" namespace doesn't work on WinRT application.
Then, uses this code to create and launch a new email.
// Create your new email message.
var em = new EmailMessage() ;
// Add as much EmailRecipient in it as you need using the following method.
em.To.Add(new EmailRecipient("yourname#yourdomain.com"));
em.Subject = "Your Subject...";
em.Body = "Your email body...";
// You can add an attachment that way.
//em.Attachments.Add(new EmailAttachment(...);
// Show the email composer.
await EmailManager.ShowComposeNewEmailAsync(em);
I hope it will solve your (or other developers) problem.
Regards.
It's always possible to connect to an SMTP server and issue commands like HELO, MAIL, RCPT, etc. Of course you'll need an SMTP server to connect to. I use this on our corporate intranet to send emails.

Categories

Resources