Outlook 365 get Mail Item - outlook

I have following problem:
We have an Outlook Addin (VSTO), with which we archive emails (orders) in SAP.
Now the plugin should be implemented for Outlook 365. I already looked at the new api and i get die subject or maitext but there seems no way to get to the raw .msg file.
So my question now is, is there a way to get an mailitem as an .msg file (or any other format)?

There are two ways may be you can try
Use the process to run the .msg
string file= #"C:\PWS\myMail.msg";
Process.Run(file);
Use OpenSharedItem to open it:
var app = new Outlook.Application();
var item = app.Session.OpenSharedItem(msgfile) as Outlook.MailItem;
//Do stuff with the mail.
item.Close(OlInspectorClose.olDiscard);
app.Quit();
Marshal.ReleaseComObject(item);

Related

Outlook Add-in file reading from mail

I am working on a Outlook add-in. I am not able to use the method item.getAttachmentsAsync in my plugin code to load and read the content of files.
I am getting ERROR TypeError: item.getAttachmentsAsync is not a function in run time.
var item = Office.context.mailbox.item;
var options = {asyncContext: {currentItem: item}};
item.getAttachmentsAsync(options, this.callback);
My requirement is explained below,
In the plugin we have a form and few fields are populated from mail body.
And I need mail attachments to auto upload to Form.
Please suggest a better way to do that.
using getAttachmentContentAsync I am able to get the file as a blob. but the problem is we need to call this method as soon after the mail opening. otherwise getting cors error

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?

Is there any better way to launch outlook add-appointment window in bot application?

I need to launch outlook calendar appointment in bot application. I found the below code in Microsoft documentation for launching outlook email.
var message = context.MakeMessage() as IMessageActivity;
message.ChannelData = JObject.FromObject(new
{
action = new { type = "LaunchUri", uri = "mailto:someone#example.comsubject=This%20is%20the%20subject&body=This%20is%20t e%20body"
}
});
await context.PostAsync(message);
And also i tried the Microsoft.Office.Interop.Outlook to add appointment , it also doesn't work for me.
Outlook.Application outlookApp = new Outlook.Application(); // creates new outlook app
Outlook.AppointmentItem oAppointment = (Outlook.AppointmentItem)outlookApp.CreateItem(Outlook.OlItemType.olAppointmentItem); // creates a new appointment
oAppointment.Subject = apt.Subject;
oAppointment.Body = apt.Body;
oAppointment.Location = apt.Location;
oAppointment.Start = Convert.ToDateTime(apt.StartTime);
oAppointment.End = Convert.ToDateTime(apt.EndTime);
Is there any better way to launch outlook calendar appointment.
Your code must call oAppointment.Save.
What exactly are you trying to do? Silently create an appointment (then you code above needs to call oAppointment.Save) or display it to the user (then call oAppointment.Display)?
If your code is running on a server, create an iCal file and let the user download and open in (local) Outlook - it will be happy to display the appointment.
Steve mentioned you could use Microsoft Graph.
You might be able to send an ics file as a media attachment (I haven't tried).
Or you can investigate if the protocol handler outlookcal: supports deep linking.
I think this link tells you how it works in Teams
https://learn.microsoft.com/en-us/microsoftteams/platform/concepts/deep-links

VSTO (Outlook) is forcing MSG attachments to be of olEmbeddeditem type, but olByValue needed

I need to send email with .msg file attached to Lotus Notes (Domino) by using VSTO (from Outlook Add-In). When this file is received in Lotus Notes, the email body from msg file is appended to the end of the main mail.
From this problem I am assuming that the issue is in attachment type.
I am trying to set the attachment type to by olByValue by adding attachment :
mail.Attachments.Add(msgFilePath, OlAttachmentType.olByValue, 0, displayName);
but whatever type I specify, it is still set to olEmbeddeditem.
Is there any way, how to force msg attachment to be olByValue?
Thank you for any suggestion or advise.
Have a nice day.
Note: For reference I have created email in Lotus-Notes too with msg attached, sent to Outlook and than forwarded back to Lotus-Notes and msg is attached not appended to the end.
There is not much you can do in the Outlook Object Model - it always tries to be "helpful" and converts MSG files to embedded message attachments. If using Redemption is an option (I am its author), it will not change the type:
SafeMailItem sItem = new SafeMailItem();
sItem.Item = mail;
sItem.Attachments.Add(msgFilePath);

Send email attachment to a local folder

I am trying to send an email from a client PC (i.e. Windows) with an attachment and have the attachment saved to a local folder on the same client PC. I have looked at a couple of alternatives, such as MailDrop (email to dropbox) and Outlook 2003 Interop library - but want to make sure I am implementing this the best way.
Does anyone have any different ideas on a simple/elegant solution?
As long as you know Outlook will be installed on all the clients the Outlook solution works very well. You can create a file and save it, then in your outlook interop you just attach and send. You didn't specify what tools you are using but here's the basic email creation method I use for Outlook in C# (Where OutlookSetup.OutlookApp is just a static method that returns the currently open instance of the Outlook application or creates a new one if Outlook isn't open). Otherwise there are several examples here on SO of using SmtpClient to achieve similar ends.
public EmailMessage(EmailInfo emailInfo, string filenameToAttach=null)
{
Message = OutlookSetup.OutlookApp.CreateItem(OL.OlItemType.olMailItem);
Message.To = emailInfo.To;
Message.CC = emailInfo.Cc ?? "";
Message.Subject = emailInfo.Subject;
if (filenameToAttach != null)
{
Message.Attachments.Add(filenameToAttach);
}
}

Resources