Send email thru Azure AD Graph API as email alias - azure

In the Graph API explorer, you can send an email with the endpoint
https://graph.microsoft.com/v1.0/me/sendMail
and a basic json payload of
"message": {
"subject": "Meet for lunch?",
"body": {
"contentType": "Text",
"content": "The new cafeteria is open."
},
"toRecipients": [
{
"emailAddress": {
"address": "user#domain.com"
}
}
],
"from":{
"emailAddress": {
"address": "smtp:my_alias#domain.com"
}
}
}
When I send this request, it still sends the email as user#domain.com instead of my email alias.
I can still see the email alias there when i run the endpoint
https://graph.microsoft.com/beta/me/
Under proxyAddresses
I've looked over the documentation and don't see any clear example of option to send the email as alias.

We can only set from and sender properties to a different value when sending a message from a shared mailbox, for a shared calendar, or as a delegate. See details here (see form and sender) and Setting the from and sender properties. Sending email as alias is not mentioned and cannot work based on the test.
So it's not supported to send the email as alias via Microsoft Graph API.
The value of from and sender must correspond to the actual mailbox used. So the only way to send email as alias is to change alias to primary email in O365 admin center and then send email.
As a workaround, if you just want recipients to think that you are sending from alias, you can configure a delegated mailbox for your mailbox (assign sendAs rights of the mailbox to a delegated user). Delegated mailbox is actually another mailbox and needs to be assigned an Exchange Online license. Then set the from property to the delegated user who have sendAs rights for your mailbox in Microsoft Graph API. See details here. After that, when you send an email, the recipient will see it's from the delegated email.
About how to assign sendAs rights in Exchange Admin Center, please refer to Use the EAC to assign permissions to individual mailboxes. It may take several hours to take effect.
POST https://graph.microsoft.com/beta/me/sendMail
{
"message": {
"subject": "Meet for lunch?",
"body": {
"contentType": "Text",
"content": "The new cafeteria is open."
},
"toRecipients": [{
"emailAddress": {
"address": "user#domain.com"
}
}
],
"from": {
"emailAddress": {
"address": "{delegated mailbox}"
}
}
}
}

Just tested the API and verified working as of now.
https://developer.microsoft.com/en-us/graph/graph-explorer
POST https://graph.microsoft.com/beta/me/sendMail
{
"message": {
"subject": "Meet for lunch test?",
"body": {
"contentType": "Text",
"content": "The new cafeteria is open."
},
"toRecipients": [
{
"emailAddress": {
"address": "somemail#gmail.com"
}
}
],
"from": {
"emailAddress": {
"address": "myalias#contoso.com"
}
}
}
}
"from" address must be from one of your proxy/alias email addresses.
If you're using AzureAD Tenant/Client IDs to send emails, you can use the sample code below:
var msg = new Message();
msg.Subject = "test";
//... other setup
msg.From = new Recipient {
EmailAddress = new EmailAddress
{ Address = "myalias#contoso.com" }
};
await graphClient.Users["mydefault#contoso.com"].SendMail(msg).Request().PostAsync();
I tried setting msg.Sender and it doesn't work.

Related

Customized html message in microsoft azure guest invitation

This is the request body I am using to send email to the guests. However, I want to customize the customizedMessageBody using html tags and elements.
{
"invitedUserDisplayName": "Invited User",
"invitedUserEmailAddress": "invited1234#yopmail.com",
"invitedUserMessageInfo": {
"messageLanguage": "string",
"ccRecipients": [
{
"emailAddress": {
"name": "xyz#yopmail.com",
"address": "xyz#yopmail.com"
}
}
],
"customizedMessageBody": "<html>hello tiger</html>"
},
"sendInvitationMessage": true,
"inviteRedirectUrl": "https://myapps.microsoft.com"
}
As Message itself a text area. Due to the Security reason, Customizing the customizedMessageBody using html tags and elements will not be processable.
This document details the available options you have for invitation messages

Retrieving the senders name and email from an envelope?

I have a service account that is using DocuSign's polling to retrieve a list of envelopes that had a status change. These envelopes were sent by various internal users. When I go to retrieve the envelopes, I'd like to retrieve who the sender of the envelope is (sender's name and email).
I initially excepted this information to be part of the Envelope object, but it's not:
Envelope envInfo = envelopesApi.GetEnvelope(AccountId, envelopeId);
I've tried various other API calls and reviewed documentation, but none of them seem to provide a way to get the sender's name and email.
Can this information be retrieved?
There actually is a way that you can get Sender Name and Email for an Envelope via the API. First, issue a Get Envelope Audit Events request to identify the UserId of the Sender. Then, use that UserId to issue a Get User request to obtain the sender's name and email address. Here are the steps, with sample requests/responses (irrelevant info omitted, for brevity):
1) Get Envelope Audit Events
Request:
GET /accounts/{accountId}/envelopes/{envelopeId}/audit_events
Response:
{
"auditEvents": [
{
"eventFields": [
...
{
"name": "UserName",
"value": "John Doe"
},
{
"name": "UserId",
"value": "af465e97-83a6-472c-a25b-ebad10e4cc6a"
},
{
"name": "Action",
"value": "Registered"
},
{
"name": "Message",
"value": "The envelope was created by John Doe"
},
{
"name": "EnvelopeStatus",
"value": "created"
},
...
]
},
...
]
}
2) Get User (specifying the UserId from the previous response)
Request:
GET /accounts/{accountId}/users/af465e97-83a6-472c-a25b-ebad10e4cc6a
Response:
{
"userName": "John Doe",
"userId": "af465e97-83a6-472c-a25b-ebad10e4cc6a",
"email": "john.doe#test.com",
"firstName": "John",
"lastName": "Doe",
...
}
Another option (if you're creating the Envelopes with the API to begin with) would be to always specify "Custom Envelope Fields" for each Envelope at creation-time that contain the sender's name and email address. Doing it this way would let you retrieve this info with the same request you're already issuing to retrieve the envelope info (provided that you include the extra querystring parameter (include=custom_fields):
GET accounts/{accountId}/envelopes/{envelopeId}?include=custom_fields
DocuSign does not work in this way, as envelopes are linked to a user and its user's documents so no one can access the document until and unless user shares the envelopes with anyone. So there are no APIs which will inform you the sender email/name by querying DS on envelopeId. You have two ways to achieve this requirement:
Use DS Connect (recommended way), configure Connect in your DS
Account and DocuSign will push the connect messages with the sender
details in that XML message when a subscribed trigger event occurs
Another way is you need to get OAUTH access token of all your users and
then call DS APIs to know the envelopes for each user
Connect message will look like below:
<UserName>Sender Name</UserName>
<Email>SenderEmail#email.com</Email>

Disable In-Person Signer email notification to the host

I'd like to know if it's possible to disable the email notification to a host when using In-Person signing. ( sent you a document to host for an in-person signing session.)
Repro:
1 - Envelope is created using API containing 3 recipients: One In-Person captive Signer and two remote signers.
2 - Host receives an email notification.
In-Person Sign Email Notification
JSON:
`{
"status":"sent",
"emailSubject":"Contract",
"compositeTemplates":[
{
"serverTemplates":[
{
"sequence":"1",
"templateId":"<templateId>"
}
],
"inlineTemplates":[
{
"sequence":"1",
"recipients":{
"inPersonSigners":[
{
"hostEmail":"johndoe#email.com",
"hostName":"John Doe",
"signerName":"Ringo Starr",
"signerEmail":"ringostarr#email.com",
"roleName":"Signer 1",
"recipientId":"1",
"clientUserId":"1000",
"routingOrder":"1",
"embeddedRecipientStartURL":"SIGN_AT_DOCUSIGN",
"recipientSignatureProviders":[
{
"signatureProviderName":"UniversalSignaturePen_OpenTrust_Hash_TSP",
"signatureProviderOptions":{
"sms":"<phoneNumber>"
}
}
]
],
"signers":[
{
"name":"John Doe",
"email":"johndoe#email.com",
"emailNotification":{
"emailSubject":"Contract for live in person signature attached.",
"emailBody":"Contract for live in person signature attached.",
"supportedLanguage":"en"
},
"roleName":"Signer 2",
"routingOrder":"2",
"recipientId":"2",
"recipientSignatureProviders":[
{
"signatureProviderName":"UniversalSignaturePen_OpenTrust_Hash_TSP",
"signatureProviderOptions":{
"sms":"<phoneNumber>"
}
}
]
},
{
"name":"Paul McCartney",
"email":"paulmccartney#email.com",
"emailNotification":{
"emailSubject":"Contract for live in person signature attached.",
"emailBody":"Contract for live in person signature attached.",
"supportedLanguage":"en"
},
"roleName":"Signer 3",
"routingOrder":"2",
"recipientId":"3",
"recipientSignatureProviders":[
{
"signatureProviderName":"UniversalSignaturePen_OpenTrust_Hash_TSP",
"signatureProviderOptions":{
"sms":"<phoneNumber>"
}
}
]
}
]
},
"customFields":{
"textCustomFields":[
{
"value":"<salesforcecontractId>",
"required":"false",
"show":"false",
"name":"##SFContract"
}
]
}
}
]
}
],
"eventNotification":{
"RecipientEvents":[
{
"recipientEventStatusCode":"Completed"
},
{
"recipientEventStatusCode":"sent"
},
{
"recipientEventStatusCode":"delivered"
},
{
"recipientEventStatusCode":"declined"
}
],
"EnvelopeEvents":[
{
"envelopeEventStatusCode":"Delivered"
},
{
"envelopeEventStatusCode":"completed"
},
{
"envelopeEventStatusCode":"sent"
},
{
"envelopeEventStatusCode":"Declined"
}
]
}
}`
As I'm using an URL that can be accessed from my application the email notification to the host is unnecessary.
Considerations to keep in mind:
None of the recipients neither the host is a DocuSign user;
The option "Suppress emails to embedded signers" under Signing Settings is already checked;
The host will not always be a recipient.
Regards.
Remove "embeddedRecipientStartURL":"SIGN_AT_DOCUSIGN" from the inPerson recipient definition.
Specifying an embeddedRecipientStartURL causes the recipient to also receive an official DocuSign email inviting them to sign the documents. See this answer for more information.
From Official Documentation
embeddedRecipientStartURL is a sender provided valid URL string for redirecting an embedded recipient. When using this option, the embedded recipient still receives an email from DocuSign, just as a remote recipient would, but when the document link in the email is clicked the recipient is redirected, through DocuSign, to this URL to complete their actions. When routing to the URL, it is up to the sender's system (the server responding to the URL) to then request a recipient token to launch a signing session.

Outlook Mail REST API: send message with attachment

I'm trying to use next API method: https://msdn.microsoft.com/office/office365/APi/mail-rest-operations#SendMessages. Sending messages without attachments works just fine, but I can not understand how to send message with attachments.
According to docs, Message structure can contain array of Attachments with items of type https://msdn.microsoft.com/office/office365/APi/complex-types-for-mail-contacts-calendar#RESTAPIResourcesFileAttachment . Problem is in the field ContentBytes -- it is impossible to dump bytes to JSON before sending request to this API method (actually dumping any BLOB to JSON is nonsense).
How should I pass Attachments using REST API at all?
Thanks.
There's an example of passing the attachment on that page: https://msdn.microsoft.com/office/office365/APi/mail-rest-operations#SendMessageOnTheFly
I know I'm 3 years late but, you can look at this example:
https://msdn.microsoft.com/office/office365/APi/mail-rest-operations#create-and-send-messages (if you don't get forwarded to the section "Create and send messages", please scroll manually).
I know it is 365 and not Microsoft Graph but request is absolutely same.
This is basically how JSON representation of the post method looks:
https://outlook.office.com/api/v2.0/me/sendmail
{
"Message":
{
"Subject": "Meet for lunch?",
"Body": {
"ContentType": "Text",
"Content": "The new cafeteria is open."
},
"ToRecipients": [
{
"EmailAddress": {
"Address": "garthf#a830edad9050849NDA1.onmicrosoft.com"
}
}
],
"Attachments": [
{
"#odata.type": "#Microsoft.OutlookServices.FileAttachment",
"Name": "menu.txt",
"ContentBytes": "bWFjIGFuZCBjaGVlc2UgdG9kYXk="
}
]
}
}

Docusign API Invalid email address error with signature from document request with inPersonSigner recipient type

I'm currently testing an API call that will ultimately allow for an agent to provide signature and another party to sign in person. In sending the call via API Explorer I continue to receive the following response:
{
"errorCode": "INVALID_EMAIL_ADDRESS_FOR_RECIPIENT",
"message": "The email address for one of the recipients is not valid."
}
I've read in the REST API guide that this needs to be enabled for my account; it may be that my demo dev account does not have this enabled. I just need to verify whether or not that I'm not omitting any essential parameters in this call. I've tried passing in my email (as the account holder) and still receive this error. Here is my request body JSON:
{
"emailBlurb": "test",
"emailSubject": "test",
"documents": [
{
"name": "ChiropractorPlusApplication.pdf",
"documentId": "1"
}
],
"recipients": {
"inPersonSigners": [
{
"hostName": "Joe Host",
"recipientId": "1",
"name": "Name",
"email": "host#gmail.com",
"signerName": "Insured"
}
]
},
"status": "sent"
}
Thanks!
I believe you have found a bug with the REST API Explorer in that it's missing at least one field for In Person Signers. If you look at the REST API documentation you'll see that there's one more required parameter for In Person Signers, which is the hostEmail
Try adding to your JSON
"hostEmail" : "host's email address",
And I have a feeling that will do the trick. See page 275 of REST API v2 PDF for info on In Person Signers recipient type. It first shows a sample request with all the options then below that it lists the required fields for this recipient type:
http://www.docusign.com/sites/default/files/REST_API_Guide_v2.pdf

Resources