Microsoft graph send email with custom from name

Budzich, Dawid 26 Reputation points
2022-10-26T23:08:49.597+00:00

Hi,
I have a problem with Azure email sending by graph API. Let me describe the current situation.

We created an app in Azure that is in mail-enabled security group and it's a member of the shared mailbox. This mailbox has the name e.g no-reply@mydomain.com.

We have also granted Mail.Send permission in graph API with application type and consent for that was approved.

This is pseudo code of our current email client implementation in node.js

class AzureEmailClient {  
    private mailClient: Client;  
  
    constructor() {  
        const credential = new ClientSecretCredential(TENANT_ID, CLIENT_ID, CLIENT_SECRET);  
        const authProvider = new TokenCredentialAuthenticationProvider(credential, {  
            scopes: ['https://graph.microsoft.com/.default']  
        });  
        this.mailClient = Client.initWithMiddleware({  
            debugLogging: true,  
            authProvider  
        });  
    }  
  
    sendEmail({ from, subject, to, body }: EmailProps) {  
        const message: Message = {  
            from: {  
                emailAddress: {  
                    name: 'Dawid Budzich via MyApp',  
                    address: 'no-reply@mydomain.com'  
                }  
            },  
            sender: {  
                emailAddress: {  
                    address: 'no-reply@mydomain.com',  
                }  
            },  
            subject,  
            toRecipients: to,  
            body: {  
                content: body,  
                contentType: "html",  
            },  
        };  
        this.mailClient.api(`/users/no-reply@mydomain.com/sendMail`).post({ message, saveToSentItems: 'false' });  
    }  
}  

As you can see we have in the message payload set emailAddress.name. However, this attribute is not used by azure, so instead of
254513-screenshot-from-2022-10-27-01-00-31.png

We got
254487-screenshot-from-2022-10-27-00-59-44.png

Look at the from name on the second screen, it's just an email address translated into some readable string. From our POV users will put more trust to the message from first screen. So far we were using Amazon SES and in the email from SES the from name is properly set (FYI we are using a different domain for SES), right now we wanted to switch into Azure, but if we won't fix this issue, we will have to stay with using SES.

To summarize, we set the email sender name in the message payload, but it's not being used for some reason.

Thanks in advance for your comments.

Regards,
Dawid Budzich

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,059 questions
0 comments No comments
{count} votes

Accepted answer
  1. HarmeetSingh7172 4,811 Reputation points
    2022-10-27T02:51:58.193+00:00

    Hello @Budzich, Dawid

    Thanks for reaching out!

    Based on my understanding, it picks up the profile name and doesn't use the name (custom name) specified in the body of the post call. Currently, graph API doesn't support setting custom Email sender name. Since this feature/functionality is presently not available, you can submit a feature request idea using this support link, which will be monitored by Microsoft team and make the enhancements to Microsoft Graph APIs. I will also upvote for you.

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote. If you have any further questions about this answer, please click Comment.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful