When creating email messages using the New-MgUserMessage cmdlet, you might encounter the internetMessageHeaders parameter in usage examples. This parameter allows you to add custom headers to your email messages, which can be useful for various purposes such as tracking, categorizing, or processing emails in specific ways.
Internet message headers are metadata elements included in email messages, providing additional information about the message. These headers can include standard fields like From, To, Subject, and Date, as well as custom fields defined by the user or application. Custom headers can be used to add extra information that might be useful for email processing systems or for specific business needs.
Here is an example from the Microsoft documentation demonstrating how to include custom internet message headers in an email message created with the New-MgUserMessage cmdlet:
Import-Module Microsoft.Graph.Mail
$params = @{
subject = "9/8/2018: concert"
body = @{
contentType = "HTML"
content = "The group represents Washington."
}
toRecipients = @(
@{
emailAddress = @{
address = "AlexW@contoso.OnMicrosoft.com"
}
}
)
internetMessageHeaders = @(
@{
name = "x-custom-header-group-name"
value = "Washington"
}
@{
name = "x-custom-header-group-id"
value = "WA001"
}
)
}
# A UPN can also be used as -UserId.
New-MgUserMessage -UserId $userId -BodyParameter $params
In this example, two custom headers are added to the email message:
To include custom headers in your email messages, follow these steps:
Define the Headers: Create a hashtable with the name and value for each custom header.
Include the Headers in the Parameters: Add the internetMessageHeaders
parameter to the hashtable passed to the -BodyParameter
parameter of New-MgUserMessage
Below is a complete example that demonstrates creating an email message with custom headers:
Import-Module Microsoft.Graph.Mail
# Define the custom headers
$customHeaders = @(
@{
name = "x-project-id"
value = "12345"
}
@{
name = "x-client-name"
value = "Contoso"
}
)
# Define the email parameters
$emailParams = @{
subject = "Project Update"
body = @{
contentType = "HTML"
content = "<p>Dear Team</p><p>Please find the latest updates on the project.</p><p>Best Regards<br/>Jane</p>"
}
toRecipients = @(
@{
emailAddress = @{
address = "team@contoso.com"
}
}
)
internetMessageHeaders = $customHeaders
}
# Create the email message
New-MgUserMessage -UserId "jane.doe@example.com" -BodyParameter $emailParams
Custom headers can be beneficial for:
The New-MgUserMessage
cmdlet, when used with the internetMessageHeaders
parameter, allows for the creation of richly informative email messages. By leveraging custom headers, administrators can add valuable metadata to emails, enhancing tracking, categorization, and automation processes. Understanding and utilizing internet message headers can significantly improve how emails are managed and processed within an organization.
© m365corner.com. All Rights Reserved. Design by HTML Codex