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.
Related
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.
I have scenario where I would have to track the delivery of the emails I send programmatically and flag those recipients who have set either 'Out of Office" OR have the message delivery failed due to over-sized inbox OR if their email ID doesn't exist. Such instances usually send out automated replies. How can I track them? Does .NET (System.Net.Mail) offer any APIs to do it?
There's no set of checks for auto-responses that produce perfect behavior (detect all auto-replies with no false positives), but the following checks have worked well so far:
header Auto-Submitted with value other than no (see RFC
3834)
headers X-Autoreply or X-Autorespond with any value
header Precedence with value auto_reply
I don't yet have any advice for detecting message delivery failure notifications.
I am trying to send an email using c# MailMessage to a hotmail account but the emails are always going to junk.
How can i send emails directly to hotmail inbox in c#?
I don't have my own smtp server, therefore i have tried using my university smtp and other smtps like google, yahoo... but all emails were sent to junk.
Any solutions?
This is not really a C# question.
Mails are sent to spam depending on their content and their headers so you should check a few things :
You need to have a subject
you shouldn't have spammy words (sex, viagra, love, watches)
You need to have a return-to and a from address headers that match
You need to be consistent with your encoding, if you go for UTF8 send UTF8 text
You shouldn't insert images
Your links inside the mail, if any, should have their text set to the address they are going to
Using these strategies should help your email not being classified as spam.
You can always check the headers of one of the mail that went into spam. It is often described what rules were applied and where the mail failed.
In hotmail, open the Junk folder, click on the message. Hotmail will display options in the body of the message - click on "Wait, it's safe!" Hotmail will move the message to your inbox, and mark the FROM email address as safe.
There is (probably) nothing wrong with your code - it is hotmail identifying the sender and/or subject as being junk.
Although it may well be out of your control, junk email filters generally work on a weighting system, so there are things that you can do to make your email look less like spam.
To start with, check that:
your subject doesn't contain all caps or sensitive words (such as "FREE!")
your body has content
the 'from' address for the MailMessage exists.
If those are all fine, have a look through this list, this article on live.com and the Policies, Practices and Guidelines for Hotmail.
What is the content of your mail, is it text that is likely to be regarded as junk mail by spam filters? Have you tried sending to other accounts such as Yahoo or Gmail?
You can't do it from C#.
It is up to the recipient to route the messages to junk or inbox or wherever it decides to put the message. If the sender were allowed to decide where the message went on the client's side, imagine how much bigger of a problem spam would be.
One solution you can employ is to have your target mail account 'whitelist' the sender, but that may not be an option in all cases.
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.
I'm trying to send an html email to a gmail account, but for some reason, Google is stripping away the html from my email. The Html is preserved when I send to other accounts (non-gmail accounts) so I know that my html is correct.
Here's how I'm going about it:
I have an aspx page, that I use as an email template.
I grab the html from the aspx page from within a web service (done in C#)
Dynamically fill in the non-static content through c# code within the web service.
Send that as the email body.
Does anyone happen to know why gmail is removing the html?
Thanks in advance.
You need to be sure to set the IsBodyHtml property to true on your MailMessage:
var message = new MailMessage();
message.IsBodyHtml = true;
// Fill and send message here
Check out the MSDN reference for more info:
System.Net.Mail.MailMessage Members
The Html is preserved when I send to other accounts (non-gmail accounts) so I know that my html is correct.
It's not a programming issue. If it were, as you've observed, this would happen to all clients.
The issue is this: Most modern email clients allow users to choose to disallow html messages, or always view them as plain text. That could be what is happening here. You have to code to expect this, because you can't control user's preferences. If they have this enabled, and you send it as html only, it will look ugly to them.
However, for a solution to your issue, you should always be sending your mail as a Multi-Part Mime message to allow all clients to get a nice readable version.