How to read any email account from a domain using C#? - 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.

Related

Pulling recipient email address from a link within an email?

I have a C# Mailkit program that automatically sends emails to an email list. I have a web server with a database filled with email addresses and I want to incorporate an unsubscribe link within my emails. Is there any way of tracking the email address of the person who clicked the link? I essentially just want to remove the email from the database of the person who unsubscribed.
Are there any kind of special links/anything I can do to pull the user's email address after they click the link?
thank you.
"When creating email message with mailkit inside the body create unsubscribe link which contains email in query parameter.Like in my example above. That link needs to point to your web server on specific endpoint which can read email address from that query string and remove it from datsbase. – SlobodanT"
"Don't use encryption for this. Don't pass user information like emails in links. When you send a user an email, store a GUID for that user or email and include it in the unsubscribe link; something like http://example.com/unsubscribe/GUID HERE. Your unsubscribe page looks up the email or user and unsubscribes them. – Dour High Arch "

How can I check for bounce back of email?

I have searched and see many people asking about verifying weather or not an email address is valid - and the overall answer I am getting is 'this is not possible'.
This makes sense, seeing how spam companies would take advantage of it. However, I use MS Outlook client to send my emails manually, and if I send to an invalid email address, I typically receive a 'bounce back' email in response. What's the deal with this? Can't I use these bounce back emails to find the invalid email addresses I have in my system (I am already sending them emails for legitimate reasons and want to see if the email is still valid).
If that's the case, how can I do this in C#?
No, you can't. Not all email services send such a "bounce back" email in response to invalid email addresses.
Additionally, a "bounce back" email could theoretically be sent for reasons other than the provided email address not existing, and the fact that you received one doesn't necessarily mean the email address isn't there.
There really isn't a way to determine if a string of characters is a real email address (you can verify whether it is valid as an email address, but not whether or not it actually exists).
To answer the question you ask in your title, you would have to monitor the return address for incoming e-mail, and then somehow figure out if any received items are "bounce back" messages.

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.

Messaging system for 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.

Avoiding email being marked as spam when sent through gmail mail server

Hi all (before closing based on the title, please read the bottom parragraph),
I'm having some small issues with emails being sent out from the C#/ASP.Net webapp that I'm currently developing.
We don't send emails out on mass, only to a single address, sometimes with a CC address.
The emails we are sending out contain one attached file, which is a single page PDF file (They are actually invoices in PDF format).
It's happened a couple of times that our emails have been flagged as spam. The content of the email is HTML without any images, and the HTML itself is not very complicated at all (Simply 4 p tags and an a tag with a mail to).
We have a company domain set up using the Gmail smtp server, and the email account with we use to send this email is called automated.emailer.
When created the System.Net.MailMessage, I am adding a simple name to the which is "XXX invoicing" (XXX is substituting our company name) using the MailAddress constructor which takes a display name, a replyto address of Invoicing#example.com and the from address is automated.emailer#example.com. The content has been checked against many sp
These emails are fairly important, so we need to do all we can to avoid them being caught as spam. I would appreciate any ideas on why these emails would be considered spam? It may be that, in order to make sure the IP of our domain matches the IP of the mail server, we need to install an exchange. This seems like a strong approach and I'd be keen to see if anyone has solved this problem in another way.
I have tried to ask this question with as much info as possible, to avoid this question being closed, since i've seen many questions regarding email spam closed with a reference to the below question, which I read, but didn't find an answer to my question.
How do you make sure email you send programmatically is not automatically marked as spam?
Probably better on superuser.com rather than here. But have you tried looking at SPF records? Might boost your credibility to spam filters.
I use the free service over at Port25. You send an email to their verifier address and get a reply with a pretty detailed breakdown of your ham score:
http://www.port25.com/support/authentication-center/email-verification/

Categories

Resources