How To Add Mandrill Metadata Using C# - c#

We currently use Mandrill to send our emails and this is working OK.
Now we wish to capture Mandrill webhooks back into our server and annotate the appropriate email source record with the event information. In order to do this we believe we have to pass the ID of the original message to the webhook so that we can pull up that message from our server when the webhook arrives.
We believe the correct approach is to add a Mandrill metadata field to the message, but we're having trouble doing that.
We've tried the following (with variations):
Message.Headers.Add("X-MC-METADATA", "\"OriginId\": \"" + Id + "\"");
but the OriginId is never returned in the webhook and we don't see this header in the email's source. It seems that we don't have quite the right format and that Mandrill is stripping this header out.

The Metadata type accepts arrays so try wrapping the metadata with {}
Message.Headers.Add("X-MC-METADATA", "{\"OriginId\": \"" + Id + "\"}");
Check the API logs and see what the raw message looked like, it should have this content somewhere like:
X-MC-Metadata: { \"testkey\": \"testvalue\"}
What I am doing is storing all the metadata in a dictionary, using a JSON converter to create the string and then stripping out all /n /r characters. The end resulting string is set as the header value.

Related

Outlook Mail API returns spellcheck class names as part of html response when using List Messages

I am currently using the outlook mail api to retreive messages from a specific shared folder (List Messages Request), when i get a response from the query i want to read the body content in this case my header prefers html.
What i'm trying to achieve is string replacement from the html response.
The problem is inside my shared emails i have something like this:
Hello [UserName], further text in mail message, Regards [CompanyName].
and the response i get from the api looks like this:
<p class=\"MsoNormal\">Hello [<span class=\"SpellE\">UserName</span>],</p><p class=\"MsoNormal\"> </p><p class=\"MsoNormal\">further text in mail message, Regards [CompanyName].</p>
the response shows a spelling error has been returned with one of my string placement texts and not the other, this is not ideal because i dont want to rely on me writing some code to check if:
[<span class=\"SpellE\">UserName</span>]
exists or not, mainly because this could be subject to change at any given time and that would be a breaking change to the system.
Is there any way i can disable spell checking being returned in the html?
Try disabling spell checking in Microsoft Outlook,
File -> Options -> Mail -> Spell
either through the application or programatically by altering the configuration in the windows registry.
Look at
HKCU\Software\Microsoft\Office\11.0\Outlook\Options\Spelling
HKCU\Software\Microsoft\Shared Tools\Proofing Tools\1.0\Office\OutlookSpellingOptions
HKCU\Software\Microsoft\Spelling

How to get the message using message id in Mailkit?

I am using mail kit to send receive mail, and manage all records in my database. I am storing all user action for particular mail and then execute it using my code.
I am storing message id in the table for the unique message, now I want to get the message using messageid. Is there any way to do it?
Firstly, don't expect the Message-Id header to be globally unique. Any hacker could easily create their own message and re-use a known Message-Id to try and confuse software that depends on Message-Ids being unique.
That said, you'll need to use the IMailFolder.Search() API combined with SearchQuery.HeaderContains() to search for messages with a particular Message-Id header.
var uids = folder.Search (SearchQuery.HeaderContains ("Message-Id", "blah#blah.com"));

Get encrypted string when FETCH mail from IMAP

I'm trying to write a IMAP mail client on C#.net with TCPClient and SSL. I can get past the connection and authentication just fine but when I fetch mail from imap.google.com, it return a encrypted string that I can't read at all. Something like:
Subject: =?UTF-8?B?UmU6IDMw5pyf5a6f57+S55Sf44Gu5oOF5aCx44Gr6Zai44GX44Gm?=
My FETCH commands are as below
"$ FETCH " + number + " body[header]\r\n"
"$ FETCH " + number + " body[text]\r\n"
What do I have to do to get the header and body of the mail to display correctly?
Subject: =?UTF-8?B?UmU6IDMw5pyf5a6f57+S55Sf44Gu5oOF5aCx44Gr6Zai44GX44Gm?=
This is not encrypted at all. This is simply the subject encoded using base64 according to the MIME standard, see RFC 2047. Decoding it results in Re: 30期実習生の情報に関して.
In order to deal with such encodings you need to decode it according to the MIME standard, i.e. either read the standard and implement everything yourself or search for some existing library which implements RFC 2047.

Docusign: Is there a way to create an envelope in the 'created' state and then put it into 'sent' later?

I want to be able to create an envelope and then email the link to the signer. The code segment I came up with is:
EnvelopesApi envelopesApi = new EnvelopesApi();
envDef.Status = "sent";
EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountId, envDef);
RecipientViewRequest viewOptions = new RecipientViewRequest()
{
ReturnUrl = "https://www.docusign.com/devcenter",
ClientUserId = signer.ClientUserId,
AuthenticationMethod = "email",
UserName = signer.Name,
Email = signer.Email // does NOT send an email
};
ViewUrl recipientView = envelopesApi.CreateRecipientView(accountId, envelopeSummary.EnvelopeId, viewOptions);
The code before this segment gets the account, signer an envelope definition, etc.
This code works fine if I set envDef.Status = "sent". If I do not set that status, I get an exception from the last line of code in this segment.
I want to just have the envelope go into created status, then get the URL and send the email in my own code that does relay email.
Or, can I supply an email address and have Docusign send the email? But, in that case, what if their email fails for some reason?
The bottom line is that I want a way to deal with the problem of how to re-send the link if the email fails to get sent.
Re your stated objective:
I want to just have the envelope go into created status, then get the URL and send the email in my own code that does relay email.
This approach is not recommended, since the URL that you obtain via CreateRecipientView will timeout in a short amount of time (I believe it's 5 minutes). In other words, if the recipient does not open the email that you send them and click the link to launch their signing session within that period of time, the link becomes invalid and they'll be unable to use it to access their signing session.
Instead of using CreateRecipientView, I'd recommend that you simply specify the recipient's info (name, email, etc.) as part of the envelope definition and then DocuSign will send the recipient an email that contains a link that they can use to access their Envelope. This link will be valid for days (not minutes, like the link that you generate yourself via CreateRecipientView), so there's no requirement that the signer act on it immediately. If for some reason the recipient misplaces or does not receive the email that DocuSign sends them, you can easily have DocuSign re-send that email notification by either using the DocuSign web UI or by using the UpdateRecipient API operation with resendEnvelope=true specified (as Frederic described in his answer).
Update #1
There's no way to retrieve a long-lived link that a recipient can use to initiate their signing session. A common way to address your scenario would be the following:
Send the signer an email that contains a link that leads them to a web page that you build -- and instructions for them to click that link to launch their Envelope whenever they are ready to review/sign the document(s). (The link URL would need to contain some sort of querystring parameters that your web page could use to identify the Envelope and Recipient.)
Design your web page such that when it receives an inbound request (as it would when the recipient clicks the link in the email you send them), it uses the information in the querystring parameters to identify the Envelope and Recipient, then issues a CreateRecipientView request to retrieve the URL that will launch that recipient's signing session, and finally, automatically redirects the user to the URL that the CreateRecipientView response returns, thereby opening the Envelope for the recipient to review/sign/submit.
By following a process like this, you're able to craft/send the email that the recipient receives (instead of relying upon DocuSign to do so), and can ensure that you're only retrieving the envelope URL whenever the user has indicated that they're ready to sign (thereby avoiding the potential of the short-lived link expiring before it's used).
Update #2
For an example of how to add recipient(s) to the EnvelopeDefinition object using the DocuSign C# SDK, see this "recipe" -- specifically, see the code within the requestSignatureOnDocumentTest method. It's basically a two-step process:
1) Define each recipient. For example:
// Add a recipient to sign the documeent
Signer signer = new Signer();
signer.Email = recipientEmail;
signer.Name = recipientName;
signer.RecipientId = "1";
2) Populate the Recipients property of the EnvelopeDefinition object with the recipient(s) that you create. For example:
envDef.Recipients = new Recipients();
envDef.Recipients.Signers = new List<Signer>();
envDef.Recipients.Signers.Add(signer);
I'm going to try to answer both of your inquiries :
1) The bottom line is that I want a way to deal with the problem of how to re-send the link if the email fails to get sent.
In order to re-send the DocuSign email to your recipients, you can use the UpdateRecipient() method as such (see my C# example below). This will re-trigger the signing email to be sent one more time to the transaction recipients :
RecipientsUpdateSummary recipientsUpdateSummary =
envelopeApi.UpdateRecipients(
accountId,
envelope.EnvelopeId,
envelope.Recipients,
new EnvelopesApi.UpdateRecipientsOptions { resendEnvelope = "true" });
Here is what the official documentation states :
2) Is there a way to create an envelope in the 'created' state and then put it into 'sent' later?
Yes, it is possible.
When you create your envelope, make sure to specify the "Created" status as below :
Status = "created"
Create your envelope :
envelopeApi.CreateEnvelope(accountId, envelope);
Then, when you're ready, change the envelope status to "sent". This will trigger the emails to the recipients. Voila !
Envelope updatedEnvelope = new Envelope
{
Status = "sent"
};
envelopeApi.Update(
accountId,
envelopeId,
updatedEnvelope);

I have a url in the format www.abc.com/mypage#yourId=ASDF2345. How to read the value of yourid using c#

In my application i have a url in the format
www.abc.com/mypage#yourId=ASDF2345.
How can i read back the value of yourId parameter from the Request object in asp.net , c# ?
If it would have been
www.abc.com/mypage?yourId=ASDF2345,
then i would have got this from the QueryString collection in the Request object. But there is a # before the yourId parameter and its not being provided by the QueryString collection.
The hash you are referring to does not actually get sent to the server by the browser. It's client-side only, C# can't "see" it.
If you must have that value, you can get it with the document.location.hash property in Javascript and send it back to the server via AJAX.
This is made easier by jQuery BBQ or jQuery Address, which detect changes in the hash location, and can trigger events.
The part of the url that follows the # is called the "fragment identifier", and there is no way to access this information on the server. In fact, it's never even sent to the server -- the specification reserves the fragment identifier for the purpose of identifying a fragment of the document that is located by the rest of the url. The spec actually requires that the browser strip the fragment id from the url before sending the url in the HTTP request.
You can access the fragment id in the browser via javascript. The property is called document.location.hash.
Read it on the client side using jQuery and transfer manually to server.
Example:
var url = "www.abc.com/mypage#yourId=ASDF2345";
var hash = url.substring(url.indexOf('#')); // '#yourId=ASDF2345'
Check
And remember that the user can change the hash as he/she wants. Check the hash before using it.

Categories

Resources