Skip to content

mimshub/hack-together-graph-blazor-net7

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hack Together: Microsoft Graph and .NET 🦒

Project name: Displaying personal info and send an email via Microsoft Graph

Description:

[Try it out](https://blazor-graph.azurewebsites.net/) Untitled video - Made with Clipchamp (3)

By participating Hack Together: Microsoft Graph and .NET hackathon as beginners, we downloaded the sample code from here

We created a new app registration Hackathon.Graph.Blazor under our coporate POC Azure subscription and configured the post-login-return-url as below: image

We enriched the sample application by retrieving additional personal info and display first 10 email subjects via Microsoft Graph .

1. Display personal info like: name, mobile number, job title, and etc

<table class="table table-striped table-condensed" style="font-family: monospace">
    <tr>
        <th>Property</th>
        <th>Value</th>
    </tr>
    <tr>
        <td>Name</td>
        <td>@_user.DisplayName</td>
    </tr>
    <tr>
        <td>Mail</td>
        <td>@_user.Mail</td>
    </tr>
    <tr>
        <td>MobilePhone</td>
        <td>@_user.MobilePhone</td>
    </tr>
    <tr>
        <td>OfficeLocation</td>
        <td>@_user.OfficeLocation</td>
    </tr>
    <tr>
        <td>JobTitle</td>
        <td>@_user.JobTitle</td>
    </tr>
</table>

2. Displaying first 25 email messages

<h4 class="text-primary">Top 25 Emails</h4>
<div class="table-responsive">
    <table class="table table-hover table-borderless">
    <thead>
        <tr>
            <td>From</td>
            <td>Subject</td>
            <td>Received at</td>
        </tr>
    </thead>
    <tbody>
        @foreach (var message in _messages)
        {
            <tr>
                <td class="text-primary text-decoration-underline">@(message.From.EmailAddress.Address)</td>
                <td>@message.Subject</td>
                <td class="text-nowrap">@(message.ReceivedDateTime.Value.ToLocalTime().ToString())</td>

            </tr>
        }
    </tbody>
</table>
</div>

image

3. Send an email via Microsoft Graph

var message = new Message
{
    Subject = subject,
    Body = new ItemBody
    {
        Content = body,
        ContentType = BodyType.Text
    },
    ToRecipients = new Recipient[]
    {
        new Recipient
        {
            EmailAddress = new EmailAddress
            {
                Address = to
            }
        }
    }
};
await _graphServiceClient.Me.SendMail(message).Request().PostAsync();

image

Reference

Contributors

About

Hack Together: Microsoft Graph and .NET 🦒

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published