check/parse email account for new messages using C# - c#

I have a windows machine that i want to write a C# or VB.net program to check an email account i own. This email account is a webmail (fatcow). I can also forward it to my gmail. What libraries are available that allow me to periodically check it (every 1 minute?) and parse the data in the body/subject and then send a response email.
Ideally, this program can queue up emails that are new and check up the quue

Take a look at the Gmail API's for hooking up to a gmail account and doing various things.
https://developers.google.com/google-apps/gmail/
Also you can take a look at some of the various open source email clients.
http://www.cyberciti.biz/tips/download-email-client-for-linux-mac-osx-windows.html
Those should give you a fairly good place to start. Also I believe I have seen simplistic email client tutorials around on the internet such as:
http://www.codeproject.com/Articles/34495/Building-your-own-Mail-Client-using-C

Related

is it possible to send a mail without being logged in?

If we have a program that is used to send a mail to store information on a popular mailbox such as gmail, hotmail etc. is it possible without hardcoding the password to send a mail to itself as a logg(a text file basically)??
Since i don't have my own website or host or anything similar, i thought that using a free mailbox to save some sensor logg history to a mail adress would be easy enough.
so the main principle would be basically to send to myself a mail containing the logg and that works great. But is it possible to avoid hardcoding the password into the client? So if i want to send the log to the mail, could we possibly send it to my mail with an unknown source(it's fully okay if it would go to the trash). As it looks now, i have to enter the hardcoded credentials into the program and then send to myself, otherwise it wont get it :(
Yes. You can create your own stmp server and connect it to your own e-mail. If you want to stay anonymous per se, you can use a temp mail.
C# xample can be found here: https://www.c-sharpcorner.com/article/sending-email-with-C-Sharp-using-smtp-servers/
You can, however, use almost any programming language to make an stmp server.

How to send Message Disposition Notification Email in node.js or C#/.NET?

I'm including a mail client in a software, and need to manage the "acknowledgment of receipt" sent with some e-mails.
Asking for one is simple, and implemented by the majority of librairies. What I'm searching is a way to (easily) generate an MDN mail in accordance to the standard defined here : https://www.rfc-editor.org/rfc/rfc3798#section-2.1, to reply to "read receipt" requests.
My software is in C#/.NET, and (for reasons) the e-mails are sent by a server in Node.js.
I could read and implement the standard by myself, but I don't want to reinvent the wheel, so I would like to know if a free library exists, in Node.js or in C#/.NET, allowing to automatically create an MDN mail. Alternatively, a good "How to" tutorial would be appreciated.
Thanks in advance for your help !
Edit :
I can't use the default behaviour of my mail server. I'm using my mailbox as a "buffer" : every mail I receive is processed and deleted from the mail server by my own custom server.
It is a bit tricky thing and depended from email server settings.
You could use cross-platform ImapClient:
http://www.imapx.org/
for extracting email notification from your email box in you application code . Your email server should support sending receive notification messages.
You can add custom data in header emails and extract it from notification body for distinguishing what exactly was pontificated.
for all types protocols you could use that (.Net):
https://www.emailarchitect.net/eagetmail/kb/csharp.aspx?cat=18
But the main idea remains the same - your system processes notification email from your email-box.

Email Anonymization Similar to Craigslist in C#

I am developing a site for which I would like to protect buyers by anonymizing their email addresses.Similar to craigslist's system, when a seller needs to contact a buyer they should be able to send an email to an anonymized address such as 1425415125#mysite.com which will then be routed to the user's email address.
My plan right now is to:
Set up a bucket (catch-all) inbox
Generate a random key for each buyer which will be the user specific ('1425415125' above) section of the email address
Monitor the bucket inbox and parse out this user specific section. Once I know the user, the email can be forwarded to the correct address
My questions are as follows:
Can you see any issues with the above solution
Are there any open source solutions to the existing problem
Are there any gotchas that one should be aware of when developing such a system?
Thanks in advance
JP
I did something related, though not quite the same. I setup a catch all inbox on my existing pop3 server (you probably have one already I'm guessing). I then used OpenPop.NET to read all new messages on a timer (say every 30 seconds). In my case I stopped at just processing the messagse but it's easy enough to generate a new message to the appropriate address and copy the body over, then send the new message out on your SMTP server.
One problem I see with your setup, and maybe it's just a misunderstanding on my part, is that while you are protecting the users original email address they will continue to be reachable at 1425415125#mysite.com basically forever. If I understand the way craigslist works, each posting has a different email address, and once the posting has been deleted/removed (or shortly after) the email address stops working. This makes it so that people can't just keep bugging you on that email address. The solution to this issue is easy, just make the email address coorespond to a post id or some other id rather then the users id in the database. The lookup will be just as quick but they will have a new email address each time.
You may wish to look at mail "piping" - the ability for someone to send an email to a mail server, which then gets thrown immediately to an executable, which then forwards your mail onto the recipient (by pulling the real email address from the database based on the incoming address from the piped message).
My personal recommendation would be to check out HMailServer, which has a COM API (the admin side is written in PHP, hence the requirement for legacy interop), is free and open-source, and is very well-documented. It doesn't have mail piping built-in, but is easily extensible given the API and support for scripts which run on server-side message events
HTH,
Benjamin
I think this solution will make sense and is in use in a lot of cases. The hardest part is actually receiving the messages. You can actually handle all of this within your web app if you need to. I wrote a blog post highlighting a couple of ways to receive email in your web app. It applies mainly to Rails but the concepts should be transferable.
The way you are lookimg to do it is the way I created a similar service. I would not recommend you writing your own smtp server. Use an existing mailserver and just use polling or some event based api.
The benefits of using a 3rd party mailserver is you can use existing backup and management tools on it.
Edit: I just noticed this has beed answered here with a better explanation. Pipe incoming email to a script on Windows IIS SMTP?
I do not see any problem with your setup, infact that is correct way to do because if your scheduled application fails, the emails will still be in the catch-all email box. Only once the email has been successfully delivered to somebody, the email should be deleted. You will be able to monitor and log the activity of your own application to monitor progress and failures.
I do not recommend Piping because, if for any reason piping goes successfully but your exe crashes, you will loose the email. Tracking will be difficult. Scheduling the jobs will not be possible.
If your application is independent of mail server, it is easy to manage it and replace your mail server whenever possible. It is easy to extend.
In this you will have to use some pop reader library, and schedule your application to run frequently.
In addition to email, you may consider a pull rather than push delivery mechanism, e.g: a message center web frontend or RSS feed. I say this because deliverability problems to various ISPs can be very difficult to troubleshoot and in my experience your users will never believe it's their ISP.

Automatically creating email addresses and receiving emails with C#?

I'm a big fan of the email feature available in Backpack, where it creates a unique email address per backpack page, and any emails sent to that address will be posted to the page.
My question is about how best to go about creating new email addresses automatically, and listening for new emails sent to those addresses. I'd like to do this from a C# service (I'm not using ASP.Net)
Has anyone tried to achieve this or
something similar before?
Are there libraries (preferably
FLOSS) already available which do
this or would assist me?
Is it possible to do this using a cloud-based
email service (and if so, what service?) and a
library for communicating with that
service (OpenPop.Net or similar)?
If your email provider supports setting up wildcard email on your domain, then you can do this with a single email account.
For example, Google Apps for Domains allows setting *#example.com to be delivered to myaccount#example.com. When someone emails sales#example.com or contact#example.com it will all be delivered to myaccount#example.com.
Then it's a process of getting all the emails. You then look at the to header in the email, match that with the name stored in your application for that user, and then process however you wish.
Be aware that you will get spam and other incorrectly addressed emails when you use this method. You will have to deal with these yourself (eg by discarding incorrectly mail that isn't addressed to a valid account).
I haven't played around much with incoming mails, but from the top level here is what you should do.
Create email addresses for the users based on any logic and save it in the DB.
Setup a mail server with your domain name and set one email account as a "catch-all" mail account. Any mail sent to your domain would then be caught under that mail account, in case the email address is not found.
Create a windows service, that would read mails from that "Catch-All" account. There are several libraries available to read mails using POP3 or IMAP.
Read the incoming mails to check the email address it was sent to, compare it with the values stored in the DB and process accordingly.
Check this question. it might help you with reading incoming mails.
The objective isn't to create email addresses, that doesn't really happen. What you do is accept email addresses at your system, what you accept is up to you. You could set up a mail server to receive any email sent to your domain, you could then parse the email To field and extract the 'name' portion. If it matches something you are listening for then you action it accordingly.
I don't think you'll find a library for this specific activity as it's rather insular. There are plenty of ways of receiving emails directly or indirectly and processing them in C# but I won't cover that as mail handling in .Net is well documented.

ASP.NET Email Patterns

ASP.NET Webforms application.
Problem: How to implement emailling elegantly?
Many parts of the application demand it. This will include HTML emails, solutions how to handle bouncebacks etc..
I have the option to use my own SMTP server (app is hosted on a VPS), or to use the hosting providers.
I'd like to start logging here too (log4net probably)
Any suggestions for libraries to use / patterns to implement?
EDIT: http://martinnormark.com/2010/03/13/generate-html-e-mail-body-in-c-using-templates
I like having a debug catch asp.net net.mail - route all emails to a different email address in debug mode
For testing with a faked out SMTP server use ndumbster. Phil Haack has a blog post on usage - http://haacked.com/archive/2006/05/30/ATestingMailServerForUnitTestingEmailFunctionality.aspx
As you pointed out email templates are fantastic. Consider creating a template for HTML and plain text. Make sure your HTML email templates use basic HTML as a number of email clients out there are not up to modern day browser standards (eg. Outlook which uses the Word HTML rendering engine).
Log4Net is a good point to start at with logging. You can also use System.Diagnostics for simplistic tracing and debugging which can be written easily out to the event log or a file. I always prefer to have a wrapper for all logging so that logging frameworks can easily be swapped out if you find that you want to swap them out later because of a must have feature. It's also good from the point of testability as you can mock it out easily.
Really it doesn't matter which SMTP server you use as long as you don't get black listed. Make sure you check the SMTP servers IP against a DNSBL so you know if your SMTP host has a bad reputation. I highly recommend checking it using Barracuda Central's IP reputation - http://www.barracudacentral.org/lookups. Also make sure you're SMTP server does support resending when you're recipients use grey listing.
For bounce backs you can setup a POP account for it to send back to, it could be as simple as reading the emails and finding which email account the rejection came from and the subject of the previous email (which should be unique) so that you can send again later or after several bounce backs remove them from the list. To implement reading POP take a look at this thread - Reading Email using Pop3 in C#
The best pattern you can implement to save yourself loads of trouble down the road is not to send email directly from your web application. Instead, write the email (or the info you need to generate the email) to a database and have a separate process do the mailing.
Consider what happens when your smtp server is down and your app tries to send. If you have a separate process sending email you can send the email later when its back up.
Also you gain the ability to rate limit your outgoing email. If you end up with the Next Big ThingĀ® on your hands you'll be glad you now have the ability to prioritize your outgoing mail or send mailing lists in batches instead of crushing your smtp server at the high point of your site's traffic.
If you are working with bouncebacks just have this process handle that as well. Now you have the ability to log a returned email address to a blacklist and check against the same list for every outgoing email. No way you want to have to put all that in your web app.
Regardless of what else you come up with please consider just writing the email to be sent to a database and letting your app go about its business. You can still get the message going out in near real time but you can get a real good separation of concerns with little effort.
As for incoming messages, I have had great success with the hMailServer which is a free e-mail server for Microsoft Windows. It supports the common e-mail protocols (IMAP, SMTP and POP3) and can easily be integrated with many existing web mail systems. It has flexible score-based spam protection and can attach to your virus scanner to scan all incoming and outgoing email. Definitely worth looking into.
For outgoing emails, I like the patterns I've expressed in this article: .NET MailMessage, LinkedResources, AlternateViews and Exceptions

Categories