Skip to main content
Solved

Using Outlook instead of Mail app in this terminal command


Forum|alt.badge.img+2

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"

Best answer by joshuasee

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 original
Did this topic help you find an answer to your question?

11 replies

Forum|alt.badge.img+4
  • New Contributor
  • 8 replies
  • September 11, 2018

Have you made Outlook the default?


Forum|alt.badge.img+10
  • Valued Contributor
  • 193 replies
  • September 11, 2018

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
}

Forum|alt.badge.img+6
  • Contributor
  • 17 replies
  • September 11, 2018

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


Forum|alt.badge.img+2

@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/


Forum|alt.badge.img+6
  • Contributor
  • 17 replies
  • September 12, 2018

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.


Forum|alt.badge.img+17
  • Valued Contributor
  • 231 replies
  • Answer
  • September 12, 2018

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';

Forum|alt.badge.img+8
  • Valued Contributor
  • 87 replies
  • September 12, 2018

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
Forum|alt.badge.img+12
  • Honored Contributor
  • 225 replies
  • September 12, 2018

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.


Forum|alt.badge.img+2
  • Author
  • New Contributor
  • 1 reply
  • September 13, 2018

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


Forum|alt.badge.img
  • New Contributor
  • 1 reply
  • April 25, 2022

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


Forum|alt.badge.img+1
  • New Contributor
  • 4 replies
  • November 28, 2022

@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


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings