c# sending multiple email with different body to multiple recipients from outlook - c#

I have a task to send multiple emails to multiple recipients with different messages at once from outlook.
for this I have to write an Add-In, which should check the list of recipients given in To from database if is there any message for any one in the list then the message should be appended to the body, this cycle should repeat for each recipient given in To.
I can get the recipient list, check from database, append the message but problem is i could not create multiple message bodies a single mail body is sent to all recipients with all appended messages.

You will need to create separate messages (Application.CreateItem or MAPIFolder.Items.Add) if you want to have different recipient lists and/or different message bodies.

Related

How to get the email activity status from send grid for a single email sent to multiple recipients

I am sending an email (with custom arguments) to multiple recipients in To list and receiving one message id.
Now I am trying to use sendgrid email activity api to fetch email status by using the query by providing the custom argument.
In the response of this email activity, i am only receiving status of only one recipient but not getting other recipients status.
Is there anything that i am missing while sending the email or searching with email activity?
I have tried searching for the same email in sendgrid and i can see the status of individual recipients but unable to get the same information using email activity
After doing some research and investigation, I could able to fix this.
I tried to search different mails by changing the query as part of the email activity api. I have found that it is returning multiple emails. So by this, i can see that there an array of mails returning from sendgrid response.
To drill down the issue, I have sent a single email to multiple recipients. In send grid activity, I have verified each recipient email to see if there is any difference which is causing my filter to not return the data.
I found that when a mail is sent to multiple recipients, the custom arguments were being added only to the first recipient of To email addresses, first recipient of CC etc.
Below is the code that I used to send the mail in C#.
SendGridMessage msg = MailHelper.CreateSingleEmailToMultipleRecipients(from, recipients, subject, plainText, htmlContent);
msg.AddCustomArgs(uniqueArgs);
SendGrid.Response response = await client.SendEmailAsync(msg);
It was never appending these custom arguments to rest of other recipients.
To fix this I have to use "AddGlobalCustomArgs" insteadof "AddCustomArgs" to add the arguments to the mail which is adding the arguments to all the recipient mails.
msg.AddGlobalCustomArgs(uniqueArgs);
After sending a mail using this, the custom arguments are getting added to all the recipients mails. Verified this for each recipient mail sent as part of Sendgrid activity.
Now, tried running the email api with the same query filter that i have, and now I am able retrieve all the emails that I have sent with custom arguments.
Hope this answer helps

How to map incoming messages to a consumer group in Azure Eventhub

I am trying to use Azure EventHub in order to process messages and it works fine as long as I have one sender and one consumer.
I simple make my consumer listen to a specific Consumer Grooup and all is fine
Now the problem is when I send different types of messages that I want processed by different Consumer Group I dont see how that can be done
I am creating my sender like this
private static EventHubProducerClient eventHubClient = new EventHubProducerClient(eventHubConnectionString, eventHubName);
But I find no way to tell it what Consumer Group it should send to, it simple sends to hub itself and that hub has multiple resource groups
How do I decide what consumergroup gets this message?
I googled for hours without finding the way to "map" input messages from specific senders to a specific output Consumer Group
You cannot specify which message is sent to a specified Consumer group. Messages are sent to partitions, partitions are all included in each consumer group, you can check the diagram in this doc. The screenshot as below:
Now for you question: when I send different types of messages that I
want processed by different Consumer Group I dont see how that can be
done.
As a workaround, when you send messages, you can specify a property for each message. When read these messages from consumer group, you can also use the property to determine if you want to process it or abandon it.
Hope it helps.

SendBulkMailRequest Class

I'm writing custom workflow in Dynamics CRM. Has anybody used SendBulkMailRequest Class? This class we used for sending bulk mail to the contacts and the scenario is like, sending a bulk mail and later update the field in other entity for every successful mails sent.
Here is the reference link of the class. Suggestions are appreciated.
You are sending Bulk Emails to Contacts, then you are tracking the Email sent flag in Opportunity record. I assume you are having a way to find out the right opportunity to update from the contact in Email recipient. (Just curious - What are you setting as regarding of those Emails?)
My recommendation: Register a plugin on Email create, then retrieve the contact's opportunity, set the flag IsMailSent to true & do a Service.Update(Oppty)
I guess SendBulkMailRequest message is just like broadcaster, as I noticed the below comments inside code sample.
// When the bulk email operation has completed, all sent emails will
// have a status of "Pending Send" and will be picked up by your email
// router. Alternatively, you can then use BackgroundSendEmail to download
// all the emails created with the SendBulkEmail message.
// See the BackgroundSendEmail sample for an example.

Outlook Add-In - Custom Headers for Email Tracking

We have written an Outlook add-in in C#, that appends a custom header to outgoing messages.
This add-in has to use a library called Redemption to bypass Outlook's security to modify the headers, and this is all working great.
Our problem lies when sending outgoing mail through an exchange server. We use the additional header as such:
Add a References header with an email address that includes an ID for tracking with our system.
This is a standard email header that all mail clients should pass on when replying to messages. So replying to a message will automatically keep the new message tracked.
All of this works just fine if you send an email from an IMAP account setup in Outlook such as GMail.
Problem is, if you send mail via an Exchange account, the Exchange server overwrites the References header and uses it's own proprietary headers: Thread-Index and Thread-Topic. Email standards suggest to use References and In-Reply-To headers. See this link on this issue.
Does anyone know a way around this? Some algorithm to gain us the following:
Add a header (of any name or kind) to emails that includes a 10-digit ID and 3 letter prefix
Replying to this email from all (or most) mail clients preserves the custom header
I think the following algorithm is going to solve our issue:
Our Outlook add-in will set the References and an arbitrary X- header
Our mail filter will look for References, if found use it (if outgoing mail server was Exchange, it will not be present)
If our mail filter finds the arbitrary X- header and a Thread-Index, it will store the data found in the X- header.
Later if the email is replied-to several times, the mail filter will use the Thread-Index to look up the past info to keep the email tracked.
For those wanting to know internals of the Thread-Index header, it is a Base64 encoded string. The first 22 bytes are the original unique portion and each reply adds an additional 5 bytes on to it. We only use the first 22 bytes to identify the email.

How to group e-mails by thread?

I need to recognize if email message is an response for message sent by my application, to put it into same email thread (something like gmail does). How can I mark an email or what data let me to recognize if it's an answer for one of previous messages in a thread?
I'm connecting through IMAP protocol, but I can easily switch to pop3 if it will be easier...
When you send your e-mail, include a Message-ID header with some globally-unique ID for your message.
When you get the response, it should have a References header that refers to your original Message-ID.
The 'In-Reply-To' header of the child should have the value of the Message-Id header of the parent.
There is one another field in header 'References' which contains message ids of all its parent.
you can user either of them as per your requirement.

Categories