Messaging system for c# - c#

I am trying to find a solution that can handle messaging via email.
When a user creates a message in my application, an email is sent using subject #4857474.
Then, the email recipient can reply, without changing the subject, and my application would know what message it used, based on the #id in the subject.
Now, I do not want to implement such service because its rather complex. What I am looking for is a service that provides this, and just calls my web services for a request when a new message has arrived.
Is there such thing? Thanks!

In the smtp standard there are two header fields that can be used for this: message-id and in-reply-to.
Assign a unique message id when you send the mail, then inspect the in-reply-to field in messages you receive. Since the field is hidden from user input, there is no risk that the user messes with it.

I don't think there is a default component you could use. Also it wouldn't be a very complex flow i think.
Just read out the subject and trigger your app?
Is email a must or can you also use a webbased reply form? Then you could use just a database.
Edit:
Read email from C# http://www.codeproject.com/KB/IP/despop3client.aspx
Create a thread that runs for ever and reads out the mailbox. If a email matches your criteria (subject) then trigger your webservice.

Related

Maintaining Email headers to link back to database object

I am trying to find a way I can use email headers to tie an email back to the database. Ideally, I would be able to send out an email and attach a custom email header with the ID of the database object, and then when I get a reply back from the email we would still have that header so we can match it.
Does anyone know if this is possible? I'm absolutely fine with the code side of how headers work it's just how they actually work in the real world.
It is possible, but whether it will work or not for a particular recipient is not under your control.
IETF RFC 822 stipulates the use of an X- prefix for vendor- and application specific headers, much like indie MIME types could be allocated.
Mail relays and mail clients will leave or remove such headers at their discretion. You have no means to force those headers to be retained in a reply or forward scenario.
In real-world applications that have the same requirement to refer to a database Id value (support ticket portals coming to my mind first), it is often seen that they include the GUID in the subject line and mention in the body text that the recipient should not remove or change that value lest they disrupt the automated processing of replies.
This approach is superior to the x-header in many ways:
it does not hide the fact that there is additional information transported on behalf of the recipient
it will not cause spam filters, mail relays and mail clients to automatically strip that information without the sender or the recipient noticing
it leaves the recipient free to decide if they want to forward or reply to a mailbox different from the sender's, including or excluding the Id as they see fit
If you're going to stick with the headers, look into Thread-Index and Thread-Topic. Here, as so often, Microsoft has introduced application-defined attributes without the standard prefix, and there is a chance that these are transported back with replies more reliably than x-headers just because they've been around for a longer time - ymmv.

user replying to email messages. How can you get data from users email?

I have difficulties implementing the following scenario.
Let's say you have a web site with ability to send and recieve messages between users.
User recieves an email with notification he has a new message on the software system (doesn't matter in what it is implemented). He can respond to this message by sending a reply via email or by logging into the site and replying to the 'message' using the site.
In case of the first approach if user simply replies to the email notification, how can you (as a developer) know what 'message' (ID) is the reply for?
I'm thinking the info would be stored in the MIME extensions. Are the MIME extensions transfered to the reply of the message? If yes than the solution could be to see the data of the original message notification for wich the user replyes to.
Any ideas? Thank you
The only “reliable” way would be to encode that information in the sender's address to which the user replies; you could also put it into subject or body of the message, and “hope” that the user doesn't tamper with it. There is an “in reply to (message-id)” header, but a lot of existing eMail clients don't set the header properly.
The usual mechanism is something like this: create an eMail alias prefix, and the append a message-id-code fragment to the end; for example, if this was for a purchase order confirmation, you could create an eMail alias handling addresses of the form po-*#example.com, where * is the unique message ID. Then, when you send your message out, you'd put the appropriate address in both the From: and Reply To: headers. EG:
From: "Purchase Order Confirmation (#1234)" <po-1234#example.com>
To: "John Doe" <jdoe#example.com>
Reply-To: "Purchase Order Confirmation (#1234)" <po-1234#example.com>
Subject: Confirm your order (#1234)
Depending upon your mail server, you should be able to define a “separator” character (typically - or +) that is used to split up the parts of the “local part” (left of #) of the eMail address; there is typically then another mechanism to map a prefix to a script to handle all addresses of a certain form. The script interface is often very much like CGI on the web, sending in some environment variables and piping the message itself in on the standard input. If your app is primarily web-based, you might find it more “comfortable” to gather the incoming eMail body, and POST it to a private (perhaps http://[::1]/getMailReply) handler. This may help you reuse existing code more readily.
We have set up a catch-all email address on our server - for example catch-all#myserver.com. When we send emails to users, we encode the message id and any other meta information we may need in the from address. You can obfuscate this or not, depending on what your needs are. So, for example, if the user has a new message in the system whose ID is 100, the from address of the email we send to the user would be something like reply-to-message-100#myserver.com. Make sure that whatever format you use for the from address would never generate a real email address on your mail server.
So, when the user responds to this message, it will get sent to the catch-all inbox you have set up. From here, you have a number of choices to make on how you process this email. In times past, we wrote a little scheduled service that would run every few minutes and check this inbox for new emails, process them as you like (insert into db, send more emails, whatever), and delete the message since you're done processing it. This is fragile since email clients all have slightly different ways of sending emails and it becomes difficult to parse the variety of client messages out there.
The second way we've done it is by integrating with http://postmarkapp.com/ - which has an incoming email api that should go public soon (we got in on the beta). You'd set everything up the same way only make your server's catch-all address forward to the postmark incoming address you'll set up with Postmark, and then Postmark does the message processing and calls a webhook you also set up to do what you like with the object received.
I highly recommend Postmark, but even the homespun method worked effectively, for the most part.
-M
Just a followup to the previous answer, Postmark Inbound is now live and public http://postmarkapp.com/inbound For each email sent to your specially formatted inbound email address, you'll receive a JSON formatted web hook API call with all the email components, headers, attachments sorted for you.

How do I use the Windows Mail Protocols? (C#?)

Well, for my program(s) I'd like to let the user send me an e-mail with any errors. Instead of relying on a forsaken SMTP server, I decided to let the user use his very own e-mail client to send an e-mail to a specified address.
So what I need is:
A sender (should not be changeable) (example: mysupportemail#gmail.com)
An attached file (should not be changeable) (example: "C:\a file.log")
(Optional) A body (changeable)
I hope it is possible!
You can use the mailto command for this. See http://msdn.microsoft.com/en-us/library/aa767737(VS.85).aspx for more information. Some mail clients support attachments on this. See the comments of the MSDN page for some information on this.
The mailto protocol has limitations, such as not being able to specify an attachment (some mail clients support it, but it's not in the official protocol). Your best option is probably to use the MAPISendMail function to let MAPI do the hard work. See this article for details:
Sending files via the default e-mail client
I used this technique in the past, it seems to work perfectly.
Using mailto directly from you application cause potential problems. If you have specified mail account for receive e-mails you can be sure, that someone will use it somehow to sent you spam or thousands unwanted emails. In our company we struggled with this problem many times - at last, we decided to allow our customers to report problems in any other way - web page form.
Now, when customer click 'report problem' this option displays a form for reporting bugs in default web browser. Opened link include some additional information which causing partial fill of the form opened by customer. Now, we have an intermediate layer and absolute control on server side who report problem (ip) and we can limit reporting for specified users. Next advantage of these solution is that you can forward emails to different departments depending on what form fields are marked/filled with.
Well, I have found the perfect solution!
For those who want to see it...
http://social.msdn.microsoft.com/Forums/en/netfxnetcom/thread/a75533eb-131b-4ff3-a3b2-b6df87c25cc8
http://www.eggheadcafe.com/community/aspnet/2/10019665/email-through-gmail-in-c.aspx

How to read any email account from a domain using C#?

I guess this is sort of two questions that are tied together.
Related questions have discussed how to read and parse email using pop3. I need to be able to do this, however, I want this to be able to work with any email address I need.
I am trying to allow users to submit content by emailing it to a unique email address, which will automatically know to which account the content should be associated.
Is there a good way to create these email addresses on the fly in C# and check these email accounts so for content submissions?
Alternatively is there a way to make a "wildcard" email account which gets all of the email sent to the domain and allows me to see what the to address was?
Most email servers will allow you to route all undeliverable email to a specific mailbox (though the details on how to do it will depend on the mail server). From there you should be able to get the address it was sent to from the To header of the message.
A much better method is to skip the inbox/POP-checking altogether and have your MTA (Message transfer agent) "send" incoming emails straight to your application.
Here's an example setup with PHP: http://www.evolt.org/incoming_mail_and_php
Alternatively is there a way to make a
"wildcard" email account which gets
all of the email sent to the domain
and allows me to see what the to
address was?
Yes its called catch all:
http://en.wikipedia.org/wiki/Catch-all
It depends on your domain host/who you are using to handle your email on the specifics of how to do it.

Sendgrid Emails - Result handling and tracking

I am looking at the c# .Net libraries from sendgrid to send emails from my applications. I can only see a DeliverAsync method within Web and I don't see any Deliver method as shown in some examples..
1) if I want to know the result of that email(success/Failed/smtp status codes), How and where do I get that information? Is there any result object?
2) if I want to track the status of the email later like whether it sent to spam or user opened it How can I do that. DO they have any tracking number/id for the email which I can get from the result object and use it later to get status through their API?
I am new to using Sendgrid libraries. So any help is appreciated.
Thanks
There's no result object in the sending of the message, since that can take some time.
The best way is to leverage the Event Webhook, so that you can receive POSTs with JSON data about your messages. you can even leverage unique_args to positively relate events to a particular message.
Depending on what you want to do, you might want to try a templating API, like sendwithus. They'll integrate with SendGrid events for you and give a UI showing events and status of every email.

Categories

Resources