Can't access SingleValueExtendedProperties when recipient account differs from sender - c#

I seem to be unable to access the SingleValueExtendedProperties set in my MVC App using the Microsoft Graph API from the recipient account.. When checking the same message in either the senders Sent Items or sending the same message to myself, it all works fine?
The SingleValueExtendedProperties just appear null when trying to access a message sent from an account that differs from the recipient, the exact same code is used for both situations, and the GUID the properties are assigned with is identical.
Here is my generation of the message:
Message newMessage = new Message()
{
ToRecipients = new List<Recipient>()
{
new Recipient() { EmailAddress = recipient }
},
Subject = message.Subject,
Body = new ItemBody()
{
Content = message.Content
},
SingleValueExtendedProperties = new MessageSingleValueExtendedPropertiesCollectionPage()
{
new SingleValueLegacyExtendedProperty()
{
Id = String.Format("String {{{0}}} Name {1}", guid, "ValueOne"),
Value = prop1
},
new SingleValueLegacyExtendedProperty()
{
Id = String.Format("String {{{0}}} Name {1}", guid, "ValueTwo"),
Value = prop2
}
}
};
And here is my send request:
await client.Me.SendMail(newMessage, true).Request().PostAsync();
And my get request:
var message = await client.Me.Messages[messageId].Request()
.Expand("singleValueExtendedProperties(
$filter=id eq 'String {guid} Name ValueOne' or id eq 'String {guid} Name ValueTwo')")
.GetAsync();
As I said, this all works flawlessly when sending mail to the same account as the sender, or reading the message from the senders Sent Items, but when receiving from a different account to the sender, the singleValueExtendedProperties are always null!

Related

I can't send message in chat, with Microsoft Graph API "Message POST is allowed in application-only context only for import purposes"

I work at a company that asked me for an API that sends messages in a private chat in Teams
After my studies, I found the Microsoft Graph API and found out how to do it, in this link I can do it
In this link I create the chat and send a message in the chat I created, from the id given to me when creating the chat
But when I do that, on my system it doesn't work
How I'm doing:
1- Create the Application
Here is my app permissions on azure
Image with permisions
2 - I create a chat, and get the id that this call returns
This is the code i make for do this, i take the id after this
var user_email = IT.DsEmail;
var chat = new Chat
{
ChatType = ChatType.OneOnOne,
Members = new ChatMembersCollectionPage()
{
new AadUserConversationMember
{
Roles = new List<String>()
{
"owner"
},
AdditionalData = new Dictionary<string, object>()
{
{"user#odata.bind", "https://graph.microsoft.com/v1.0/users('notificacoes#vaxxinova.com.br')"}
}
},
new AadUserConversationMember
{
Roles = new List<String>()
{
"owner"
},
AdditionalData = new Dictionary<string, object>()
{
{"user#odata.bind", "https://graph.microsoft.com/v1.0/users('" + user_email + "')"}
}
}
}
};
var user = await graphServiceClient.Chats.Request().AddAsync(chat);
This works! I get the id with this call, and this id I would use to send the message
3 - Send a mesage in private chat
Now dont work!
This is my code
var chatMessage = new ChatMessage
{
Body = new ItemBody
{
Content = "Hello world"
}
};
await graphServiceClient.Chats["19:35fa8078-de1a-4ec1-bb8f-85f1d4e14fa9_8848a24c-c679-415c-ac14-7f9dde86d6ec#unq.gbl.spaces"].Messages
.Request()
.AddAsync(chatMessage);
When i do that, i receive this error
Unauthorized\r\nMessage: Message POST is allowed in application-only context only for import purposes. Refer to https://docs.microsoft.com/microsoftteams/platform/graph-api/import-messages/import-external-messages-to-teams for more details.
Can someone help me? Because in that link to test I can create the chat and send the message, but in the system I'm creating I can't?
And why in my system I can create the chat, but I can't send the message?
I create the aplication, i create the chat, but i receive a error when i tried send a mensagem

Error when calling CreateEnvelope: Invalid Username For Recipient

I am using the updated DocuSign API with my .NET application and for the Authentication, I'm using the Authentication Code Grant workflow using 'signature%20extended' as the Code. I can successfully authenticate and get back an access token for the user I'm authenticating with.
I then get the Account details without any issue
ApiClient apiClient = new ApiClient("https://demo.docusign.net/restapi");
var docuSignUserInfo = apiClient.GetUserInfo(accessToken).Accounts.FirstOrDefault();
I then proceed with creating my Signer and Document Model
Document document = new Document
{ DocumentBase64 = Convert.ToBase64String(ReadContent(docName)),
Name = "Lorem Ipsum", FileExtension = "pdf", DocumentId = "1"
};
Document[] documents = new Document[] { document };
// Create the signer recipient object
Signer signer = new Signer
{ Email = "test#example.com", FirstName = "Jane", LastName="Doe" ClientUserId = "1000",
RecipientId = "1", RoutingOrder = "1"
};
Signer[] signers = new Signer[] { signer };
Recipients recipients = new Recipients { Signers = new List<Signer>(signers) };
EnvelopeDefinition envelopeDefinition = new EnvelopeDefinition
{ EmailSubject = "Please sign the document",
Documents = new List<Document>( documents ),
Recipients = recipients,
Status = "sent"
};
ApiClient apiClient = new ApiClient("https://demo.docusign.net/restapi");
apiClient.Configuration.AddDefaultHeader("Authorization", "Bearer " + accessToken);
EnvelopesApi envelopesApi = new EnvelopesApi(apiClient.Configuration);
//This is the API call that throws the error below
EnvelopeSummary results = envelopesApi.CreateEnvelope(accountId, envelopeDefinition);
Error calling CreateEnvelope: {
"errorCode": "INVALID_USERNAME_FOR_RECIPIENT",
"message": "The user name for the recipient is invalid. Envelope definition is missing a UserName for recipientId: 1"
}
From my understanding, I shouldn't need to specify any Username/Passwords as I'm using the Access Token for Authentication. Also, I don't understand why a recipient would require a UserName?
I think you need to provide the Name property for the Signer model. Please try that.
I agree that the FirstName and LastName sound like they are all that is needed, but those attributes may not be fully implemented yet (or a bug).
Please advise if this solved your problem. Thank you.
Added
The FirstName and LastName attributes are optional. DocuSign internal bug report DEVDOCS-1079 has been filed to have the documentation for those fields improved.

DocuSign SIGNING_GROUP_INVALID with Certified Delivery

I already use DocuSign API.
When I create an envelope, I usually send it to 2 recipients: 1 signer (with embedded authentication) and 1 certified delivery.
But now I would like to use a signing group as the certified delivery.
I use the DocuSign.eSign.dll NuGet package. My code is something like this:
public async Task CreateEnvelopeAsync(ContractRequest contract, Dictionary<string, string> customFields)
{
//do stuff...
var envelope = new EnvelopeDefinition
{
EmailSubject = name,
Status = "sent",
Documents = new List<Document>
{
new Document
{
Name = $"{name}.pdf",
DocumentBase64 = contract.DocumentBase64,
DocumentId = "1"
}
},
Recipients = new Recipients
{
Signers = new List<Signer>(),
CertifiedDeliveries = new List<CertifiedDelivery>()
},
CustomFields = new CustomFields { TextCustomFields = new List<TextCustomField>() }
};
//do more stuff...
var signer = CreateSigner(recipient, recipientId);
envelope.Recipients.Signers.Add(signer);
var reviewer = CreateReviewer(recipientId, recipient, "174339");
envelope.Recipients.CertifiedDeliveries.Add(reviewer);
//do even more stuff...
var envelopeSummary = await _EnvelopesApi.CreateEnvelopeAsync(_AccountId, envelope).ConfigureAwait(false);
}
static CertifiedDelivery CreateReviewer(int recipientId, Recipient recipient, int signingGroupId)
{
return new CertifiedDelivery
{
RecipientId = $"{recipientId}",
RoutingOrder = $"{recipient.SignOrder}",
SigningGroupId = $"{signingGroupId}"
};
}
But I get the following error:
Error calling CreateEnvelope: {\r\n \"errorCode\":
\"SIGNING_GROUP_INVALID\",\r\n \"message\": \"Invalid signing group
supplied. Invalid group for the account\"\r\n}
So, I have 3 questions:
1) Is it possible to send a signing group as a certified delivery?
2) If the previous is possible, is it also possible to send a signing group as a certified delivery if I am already sending a signer with embeded authentication?
3) If both are possible, then what am I doing wrong?
The signing group id that I'm passing really exists:

Sendgrid C# bulk email X-SMTPAPI header not working

I am trying to send email with SendGrid to multiple recipients in an ASP.Net C# web application
According to the SendGrid documentation I need to add X-SMTPAPI header to my message in JSON formatted string. I do so, for first check I just added a hand-typed string before building my json email list progamatically here is my code:
string header = "{\"to\": [\"emailaddress2\",\"emailaddress3\"], \"sub\": { \"%name%\": [\"Ben\",\"Joe\"]},\"filters\": { \"footer\": { \"settings\": { \"enable\": 1,\"text/plain\": \"Thank you for your business\"}}}}";
string header2 = Regex.Replace(header, "(.{72})", "$1" + Environment.NewLine);
var myMessage3 = new SendGridMessage();
myMessage3.From = new MailAddress("emailaddress1", "FromName");
myMessage3.Headers.Add("X-SMTPAPI", header2);
myMessage3.AddTo("emailaddress4");
myMessage3.Subject = "Test subject";
myMessage3.Html = "Test message";
myMessage3.EnableClickTracking(true);
// Create credentials, specifying your user name and password.
var credentials = new NetworkCredential(ConfigurationManager.AppSettings["xxxxx"], ConfigurationManager.AppSettings["xxxxx"]);
// Create an Web transport for sending email.
var transportWeb = new Web(credentials);
// Send the email, which returns an awaitable task.
transportWeb.DeliverAsync(myMessage3);
But it just seems to ignore my header, and sends the email to the one email "emailaddress4" used in "addto".
According the documentation if the header JSON is parsed wrongly, then SendGrid sends an email about the error to the email address set in "FROM" field, but I get no email about any error.
Anyone got any idea?
For me using the latest 9.x c# library the only way I could solve this was by using the MailHelper static functions like this:
var client = new SendGridClient(HttpClient, new SendGridClientOptions { ApiKey = _sendGridApiKey, HttpErrorAsException = true });
SendGridMessage mailMsg;
var recipients = to.Split(',').Select((email) => new EmailAddress(email)).ToList();
if (recipients.Count() > 1)
{
mailMsg = MailHelper.CreateSingleEmailToMultipleRecipients(
new EmailAddress(from),
recipients,
subject,
"",
body);
}
else
{
mailMsg = MailHelper.CreateSingleEmail(
new EmailAddress(from),
recipients.First(),
subject,
"",
body);
}
if (attachment != null)
{
mailMsg.AddAttachment(attachment.Name,
attachment.ContentStream.ToBase64(),
attachment.ContentType.MediaType);
}
var response = await client.SendEmailAsync(mailMsg).ConfigureAwait(false);
if (response.IsSuccessStatusCode)
{
_log.Trace($"'{subject}' email to '{to}' queued");
return true;
}
else {
throw new HttpRequestException($"'{subject}' email to '{to}' not queued");
}
I'm not sure why you wouldn't recieve any errors at your FROM address, but your JSON contains the following flaws:
, near the end makes the string invalid json
spaces around the first % in %name%, that might make sendgrid think it's an invalid substitution tag
if you use the X-SMTPAPI header to specify multiple recipients, you are not supposed to add a standard SMTP TO using AddTo().
Besides that, you didn't wrap the header at 72 characters (see the example in the documentation).
I figured that however the X-SMTPAPI documentation talks about passing the header as JSON, the API itself expects it as a parameter, containing Ienumerable string. So the working code is:
var myMessage3 = new SendGridMessage();
myMessage3.From = new MailAddress("email4#email.com", "Test Sender");
myMessage3.AddTo("email2#email.com");
myMessage3.Subject = "Új klubkártya regisztrálva";
myMessage3.Html = "Teszt üzenet";
myMessage3.EnableClickTracking(true);
/* SMTP API
* ===================================================*/
// Recipients
var addresses = new[]{
"email2#email.com", "email3#email.com"
};
//string check = string.Join(",", addresses);
myMessage3.Header.SetTo(addresses);
// Create credentials, specifying your user name and password.
var credentials = new NetworkCredential(ConfigurationManager.AppSettings["xxxxxxx"], ConfigurationManager.AppSettings["xxxxxxxxx"]);
// Create an Web transport for sending email.
var transportWeb = new Web(credentials);
// Send the email, which returns an awaitable task.
transportWeb.DeliverAsync(myMessage3);

Sending raw WNS notifications using message attributes

I am attempting to send a raw notification to WNS by setting message attributes, but it appears that a toast notification is being sent instead.
Here is the C# code I'm using to build the publish request.
var request = new PublishRequest()
{
TopicArn = TOPIC_ARN,
Message = "Test Message",
MessageAttributes = new Dictionary<string, MessageAttributeValue>()
{
{ "AWS.SNS.MOBILE.WNS.Type", new MessageAttributeValue() { StringValue = "wns/raw", DataType = "String" } }
}
};
From what I can tell, I am setting the X-WNS-Type correctly using SNS
Message Attributes, but the notification is still received as a toast on the client. Are there any examples of somebody doing this successfully?
I was able to get it working by using MessageStructure. Setting the value to json and updating Message to have a message specifically for WNS did the trick. My assumption is that the WNS value for MessageAttributes only applies if a message is defined specifically for WNS.
var request = new PublishRequest()
{
TopicArn = TOPIC_ARN,
Message = "{ \"default\": \"default message\", \"WNS\" : \"raw message\"}",
MessageAttributes = new Dictionary<string, MessageAttributeValue>()
{
{ "AWS.SNS.MOBILE.WNS.Type", new MessageAttributeValue() { StringValue = "wns/raw", DataType = "String" } }
},
MessageStructure = "json",
};

Categories