Using Outlook instead of Mail app in this terminal command

Saljuhani
New Contributor

Hello,

I have this script that emails a bunch of information to our helpdesk, however it is currently using the native mail app on macs. Is there a way to edit it to use the Outlook app instead?

email computer information to help desk

currentUser=$( stat -f "%Su" /dev/console )

sudo -u "$currentUser" /usr/bin/open "mailto:support@company.org?subject=Computer Information ($serialNumber)&body=$displayInfo"

1 ACCEPTED SOLUTION

joshuasee
Contributor III

Though I would recommend addressing setting the default mail client as mentioned above, the command below should do what you want:

/usr/bin/open -b com.microsoft.outlook 'mailto:foo@bar.com?subject=Computer%20Information';

# Variant for when you're in a different security context, requires root:
/bin/launchctl asuser $(/usr/bin/stat -f%Su /dev/console) /usr/bin/sudo -iu "$(/usr/bin/stat -f%Su /dev/console)" /usr/bin/open -b com.microsoft.outlook 'mailto:foo@bar.com?subject=Computer%20Information';

View solution in original post

11 REPLIES 11

mfurman
New Contributor II

Have you made Outlook the default?

m_donovan
Contributor III

Our users can use either so I have a self service script that asks which one they use and creates the email for it. Here is the function for outlook:

sendOutlook(){
echo "tell application "Microsoft Outlook"
    set theContent to ("You are logged in as: ${USERNAME} <br> Computer name:   ${MACNAME} <br> Computer Hostname:   ${MACHOSTNAME} <br> Serial Number:   ${compSerial} <br> IP Address:   ${IPADDRESS} <br> MAC Address:     ${MACADDRESS} <br><br> Barcode: Enter Barcode Here <br><br> Type a brief description of the problem or request: <br><br> ")
    set newMessage to make new outgoing message with properties {subject:"Staff Laptop ${MACNAME}", content:theContent}
    make new recipient at newMessage with properties {email address:{name:"HEAT Helpdesk", address:"heat.helpdesk@your.org"}} 
    open newMessage
end tell" | osascript
}

dmaestre
Release Candidate Programs Tester

Launch the Mail.app and then within Preferences make sure Outlook.app is your default emailing client.

hafizulla_chitt
New Contributor III

@Saljuhani,

I hope this will help you.

You can create New policy & make available to users in self service.

SetDefaultMailApp (Download Here): This utility allows you to easily make Microsoft Outlook the default mail application.

Why use it: You want Outlook to open a new email whenever you click on a mailto: link in an email or website. Clicking on a mailto: link opens the default email application and Outlook is not the default mail application until you set it.

How to use:

Open SetDefaultMailApp utility.
Choose “com.microsoft.outlook” in the Default Mail Application dialog and click the “Make Default” button. Once set, you can quit Default Mail Application.

https://blogs.technet.microsoft.com/office_for_mac_support_team_blog/2017/08/10/mac-outlook-support-utilities/

dmaestre
Release Candidate Programs Tester

Nice Utility. Unfortunately, I try to use this with JAMF and the Admin Console doesn't like it. Even if packaged correctly. Not a big deal though.

joshuasee
Contributor III

Though I would recommend addressing setting the default mail client as mentioned above, the command below should do what you want:

/usr/bin/open -b com.microsoft.outlook 'mailto:foo@bar.com?subject=Computer%20Information';

# Variant for when you're in a different security context, requires root:
/bin/launchctl asuser $(/usr/bin/stat -f%Su /dev/console) /usr/bin/sudo -iu "$(/usr/bin/stat -f%Su /dev/console)" /usr/bin/open -b com.microsoft.outlook 'mailto:foo@bar.com?subject=Computer%20Information';

tak10
Contributor II

You can set the default mail client to MS Outlook.

#!/usr/bin/python

from LaunchServices import *

LSSetDefaultHandlerForURLScheme("mailto", "com.microsoft.outlook")
LSSetDefaultRoleHandlerForContentType("com.apple.ical.ics", kLSRolesAll, "com.microsoft.Outlook")
LSSetDefaultRoleHandlerForContentType("public.vcard", kLSRolesAll, "com.microsoft.Outloook")

rqomsiya
Contributor III

There is also a great tool by @pbowden and his team that automatically sets the Mail client to default to Outlook:

https://macadmins.software/tools/

Look for the app called: MailToOutlook

Its a .PKG that you can push from self service. The only caveat is that it seems like the user has to be logged in. You can effectively make this a SS policy.

Saljuhani
New Contributor

Thank you all for the responses. This seems to have fixed the issue

https://www.jamf.com/jamf-nation/discussions/29313/using-outlook-instead-of-mail-app-in-this-terminal-command#responseChild172243

sergepole
New Contributor

Hello -- and thanks for the "How to" on building an Outlook email in bash.  BUT !! how do you then send the just-created email ?  It's probably obvious, but I can't figure this one out.

Stay safe & healthy -

Serge

JRMcNair
New Contributor II

@sergepole  did you figure out how to send the newly created email?

I am looking for how to do the same thing.

Thank you,

John