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