Posted on 09-11-2018 01:08 PM
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?
currentUser=$( stat -f "%Su" /dev/console )
sudo -u "$currentUser" /usr/bin/open "mailto:support@company.org?subject=Computer Information ($serialNumber)&body=$displayInfo"
Solved! Go to Solution.
Posted on 09-12-2018 12:02 PM
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';
Posted on 09-11-2018 01:32 PM
Have you made Outlook the default?
Posted on 09-11-2018 01:41 PM
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
}
Posted on 09-11-2018 01:41 PM
Launch the Mail.app and then within Preferences make sure Outlook.app is your default emailing client.
Posted on 09-12-2018 02:20 AM
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/
Posted on 09-12-2018 10:55 AM
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.
Posted on 09-12-2018 12:02 PM
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';
Posted on 09-12-2018 12:31 PM
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")
Posted on 09-12-2018 01:06 PM
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.
Posted on 09-13-2018 09:01 AM
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
Posted on 04-25-2022 02:48 PM
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
11-28-2022 12:25 PM - edited 11-28-2022 12:26 PM
@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