Coding a function to create an Outlook .msg file

Moving from Classic to Kinetic.
In Classic I had a function that created an Outlook email. The classic customized screen code populated it and opened it on the users screen for a final check before sending.
Since, in Kinetic, all functions and code now run on the server that’s become problematic. My Initial thought was to copy Microsoft.Office.Interop.Outlook.dll to the server and create the email there. But it can’t even get based the first line of code before crashing.

Microsoft.Office.Interop.Outlook.Application App = new Microsoft.Office.Interop.Outlook.Application();

I’ve copied over the .dll and set my reference and using.
It just crashes right here.

A REAL coding area with better inline assistance and a good method of doing line by line debugging would really help. I feel that toolset is not really at ‘release ready’

Is Office installed on the server hosting this? Assuming it’s a server within your control.

It likely never will given how little attention tools gets. An idea can be submitted on specific asks and I bet many in this community would be incentivized to vote for those changes.

That was my thought to. I’m trying the install now. A LOT of my Classic customizations rely on this type of local client access. It’s annoying and there are insufficient tools to fix it well.

Instead of creating a draft msg, could you have a BPM prompt to review the message content before sending from the server?

1 Like

I might have to. Some kind of HTML display to show the formatted email before sending but extra step to redo what I had before in a simpler manner.
I love functions for doing things with data on the server but the client side is more difficult.

1 Like

How complicated is the email? Very simple emails could be made with just a URL I think:

2 Likes

Great idea! I have used this approach in other web apps, but not within Kinetic. Should work

I’ve done this in Kinetic. It works for simple emails.

Are you a M365 user?

If so, you can make a REST call from the server to create a draft. Nothing to install and it will work with users who are not on Windows (iOS, Android, Mac).

The tricky part will be authentication.

4 Likes

Both Chat-GPT and Claude came up with plausible solutions for creating a .eml file with just native .net framework libraries, which if downloaded should open in outlook.

I think @Mark_Wonsil solution is the cleanest as long as you use M365

Automation studio would make authentication easy.

1 Like

:face_with_raised_eyebrow:

Using a service account that can write to anybody’s draft folder or a true on-behalf of flow where the user’s actual access token is used? :thinking:

Would the draft go into the endusers draft box?

1 Like

Automation studio and email is a nightmare.

As a security person, I would never allow that lol. We don’t allow service accounts have access to mailboxes like that.

1 Like

I am but we’ve been using an onsite SMTP server doing a relay for this kind of email. So maybe I need to revist it.

I get what you are saying. We use Role Based Access Control for Applications in Exchange Online to at least scope the application’s api permissions down to the groups that actually need access (in our case 4 people in 1 role). I’d love to hear if someone knows of a better way.

1 Like

I suppose you could create the .MSG file at the server and send it to the user as an attachment.

Why does it need to be outlook? Why can’t it just be an email message sent via SMTP or the graph API?

1 Like

The users review the draft for correctness before it’s sent. This is a final check for Engineering details etc.

1 Like