Easy methods to ship Outlook e mail, Groups messages and extra from R

Hello, I’m Sharon Machlis at IDG, right here with Episode 66 of Do Extra With R: Ship Outlook e mail, Groups messages, OneDrive recordsdata and extra – proper from R!
Microsoft’s Azure group has developed Microsoft365R, a package deal to work together with Microsoft 365 APIs. Let’s see the way it works.

Step 1 is authenticating your account. The perform you utilize for that relies on what you need to do. Let’s begin with sending an Outlook e mail message.

To authorize an enterprise Outlook account, use the get_business_outlook() perform, and save that to a variable. That variable will likely be a particular R object of sophistication ms_outlook. In case you’re utilizing a private account, the perform is get_personal_outlook() as a substitute.

It’s possible you’ll run into an issue together with your work account and see an error like this. The authorization vignette has some recommendations, which you’ll be able to see by working the bottom R vignette perform for the package deal.

The vignette hyperlinks to some extra directions, with useful recommendation. You may need to strive once more with Microsoft’s official app ID within the argument.

That appears like this – once more, that app ID isn’t something from my setup particularly; it’s Microsoft’s official app ID. And in case anybody from my IT division is watching, that is all theoretical primarily based on official recommendation from Microsoft’s Azure group! Anyway, if it really works, a browser window will pop up asking you to register after which authenticate you.

There’s lots you are able to do with the Outlook connection, together with learn and delete emails. However probably the most attention-grabbing one for me is to ship e mail. Begin by creating an e mail object utilizing the create_mail() technique of your ms outlook object. The physique textual content of the e-mail is the primary argument, after which you possibly can go different arguments like topic and to: area.

Once you do this, a draft e mail must be saved in your drafts folder.

There are a few different syntaxes you need to use do to this. On this one, additionally really useful by the package deal vignette, you need to use the greenback signal image virtually like a pipe and chain a number of strategies collectively. This additionally demonstrations which you can create the e-mail object with content material sort html and use html formatting in your message, and ship to a number of recipients. This additionally exhibits up in your Drafts folder.

You need to use markdown as a substitute of uncooked HTML with the blastula package deal. Right here I’m loading the blastula package deal after which saving some markdown as an R character string, in a variable blastula_body_text. You’ll be able to flip that string right into a blastula e mail object with blastula’s compose_email() perform. The character string goes into the physique argument – however wrapped in blastula’s md() perform, so compose e mail is aware of it’s markdown that must be rendered. And you then create an outlook e mail from the blastula e mail.

Which may be somewhat complicated (it was to me at first). To recap:

1. Save your markdown in a personality string
2. Create a blastula e mail object with compose_email(), and your string as the primary argument wrapped in md()
3. Flip that into an outlook e mail object with create_email()

There are just a few extra issues you are able to do with e mail objects, comparable to add an attachment with the add_attachment() technique. And, after all, ship the e-mail with the outlook e mail object’s ship() technique. In idea you must also have the ability to embrace inline photos in your e mail, however I had combined success with that so can’t actually advocate it but.

Working with Groups is analogous. You authenticate with the get_team() perform and the precise title or ID of certainly one of your Groups. Like with Outlook, this will not work in an enterprise. There’s one other particular Microsoft app ID – it’s additionally within the authentication documentation, and I’ve used that on this code. That first argument is my very own particular group title or ID. The second argument, app ID, is Microsoft’s; and everybody would use the identical one to do this technique of authentication.

After you authenticate, create a channel object from the group object with the get_channel() technique, like I did right here for the Normal channel in my Crew.

It’s fairly easy to ship a fundamental textual content message to a channel, together with an attachment if you’d like, with the channel object’s send_message() technique. That is clearly fairly fundamental.

As you’d anticipate, you possibly can run some R code first and put a variable because the send_message argument additionally.

There are related authentication and communication features for OneDrive and SharePoint to record, add, and obtain recordsdata. I didn’t have an excessive amount of success authenticating with these at work, however I arrange a check private OneDrive and it was extraordinarily straightforward to attach.

That’s it for this episode, thanks for watching! For extra R suggestions, head to the Do Extra With R web page at bit-dot-l-y slash do extra with R, all lowercase apart from the R. You may also discover the Do Extra With R playlist on YouTube’s IDG Tech Speak channel the place you possibly can subscribe so that you by no means miss an episode. Hope to see you subsequent time. Keep wholesome and protected, everybody!

Source link

Leave a Reply