C# Mail Server? - c#

I'm trying to understand exactly what it is I need to be implementing and am just after a little guidance. I know very little about email standards such as POP3, IMAP, SMTP which is probably what's making the getting started difficult.
What'd I'd like to do consists of a couple of things:
Be notified of the arrival of an email at a specific custom address. e.g. hi.me#myapp.com.
Handle multiple addresses per user.
Be able to process this email and either delete it, leave it and be able to display in a web email client or forward it on based on various rules.
I've seen a few SMTP libraries and a POP3 one, but I'm not 100% sure what I need to do this. I'm guessing the best way would be to write a full C# mail server - but I'm hoping for a little guidance/suggestion.
Thanks

If you really want to build a mailserver from scratch, the protocol specifications are all available as RFCs.
For IMAP that would be RFC-3501 and for SMTP RFC-2821, you can google for the rest.
I've been working on a C# SMTP server in my (very limited) spare time, mostly out of frustration with existing MTAs and as an exercise in C# server programming. I can tell you that there's a bit more to it than you might think. So if you want fast results, I'd seriously consider hooking into an existing MTA/mailserver setup.
Depending on how fast you want to process messages, it may be sufficient to poll one or more mailboxes. You could process the messages and, for example, forward them to another mailbox using the built-in .NET SmtpClient.
On top of that, all mail servers I know of implement not just the SMTP protocol but also a slew of anti-spam measures. Most of these measures have matured over many years. You get all that for free if you build on top of an existing mail server infrastructure.
Then again, configuration of just about any mail server I know seems to be a fine art, hence my frustration with them.

Related

Sending E-mail to localhost / "capturing" outgoing e-mail

I work with a dozen pieces of equipment whose operating software has the option to send e-mails on error. I would prefer to capture the details of that e-mail on the host PCs that run them (i.e. for logging, communicating details automatically via Slack, etc.) rather than them going to an inbox somewhere.
Is there a way to have the software e-mail an address that is essentially a lightweight piece of code running on the same PC mimicking something like an SMTP server (that will allow me to get after the message's contents)? Other solutions I have seen are along the lines of setting up a full-blown server which seems like overkill.
You may configure SmtpClient to save email to a specific folder instead of sending it over the wire. Check this answer.
Also you must design your system in the way it could work with different implementations of your 'sender', so that you can replace it when you need that, for example during testing. In this case you can easily provide proxy implementation that will capture email content and then send it to localhost, or add aspects (make retries, logs performance...).

Issuing email addresses to users

What needs to be done for an application to be able to issue email addresses, such as user123#mydomain.com?
I'm using Amazon SES to send out emails, do they have a service for this or would this have to do with the domain registrar (GoDaddy), or both?
The client to check email would be the web application itself.
I'm using C#.Net and Mvc for that as far as development is concerned but would prefer to use existing SaaS wherever possible.
What are some good ways to go?
EDIT: I checked with GoDaddy and they can't do this at scale. I don't believe Amazon does this either. How is this done?
This would all depend on your implementation of email server host. If you are running Windows with IIS and Email Post office then users are of the host domain. You can use the admin scripts for adding users from the site in this case.
If you are using Linux and a thrid party email service, it will likely have a user interface for adding users. Howerver these implementations generally use MySQL on the backend so you can add users through script from an implementation of PHP through Apache webserver host or backend service that adds users through MySQL script.
You need a mail server. As you can see from the list there are plenty of mail servers that exist, however there are some serious leaders in the field:
According to one survey, sendmail, Microsoft Exchange Server, Postfix,
and Exim together control over 85% of market share for SMTP service in
2010.1
I strongly recommend not hosting such a server in your code (if an implementation even exists, which I couldn't find)
After configuration of the mail server (which may need some intensive investment either in time or money, since this is complicated; some mail servers are notoriously complicated) you point your domain to the mail server. Mails can now be received to the email adresses you define.
This process is complicated, and I have a feeling that your question shows you don't know exactly what you need either (In fact I would have recommended closing it as too broad). I'd recommend reformulating exactly what you need and what you have so far. Don't hesitate to get in touch with someone that may help you formulate your needs.

Is there a way to forbid smtp transparent forwarding?

Problem steps :
My company sends mail to external partners (using .Net SmtpClient),
Some of them have set up "transparent forwarding" on our mails to some of their co-workers,
Those co-workers receive our mails as if we have send them directly to them (no "on behalf of", no classical "forward" from the original "To" mailbox), without any clue of which mail box has transparently forwarded them the mail.
(In fact, smtp conversation traces in the mail properties allows to find it, but most users are not tech savvy enough to be able to access such information, and we have not the knowledge for explaining them how to do for all the varieties of mail clients our partners may use),
Some of those co-workers complains to us that we are spamming them. And if their are unable to transmit us the offending mail untouched (usually as an attachment, preserving the smtp conversation traces), we are helpless in determining by which way they have got our mailing which was not originally directed to them.
Is there a way using SmtpClient to set-up some properties which forbids "transparent forwarding" ?
I do not want to forbid normal forwarding or copying as in How do I prevent Lotus Notes users from forwarding or copying a message sent via System.Net.Mail? question.
I just do want to forbid that "transparent forwarding" (which is IMHO a very bad feature of some mail systems like MS Exchange, which in its rules options gives two way of forwarding, one being "transparent").
As this feature looks to me as being not compliant to smtp RFC, I really fear the answer is no or almost no.
But if your are aware of some custom header for forbidding this on some of those mail systems who do offer that transparent forwarding feature, it may still be of some help to me if their are settable using SmtpClient.
If you are trying to solve the problem of not knowing who the original recipient of the message is, then try adding a line in the body of the message something like this...
"This message was intended for (insert recipient here)."
You can make it visible so the user can see who the original recipient was, or (if you can) put it in super small font so you can use it for troubleshooting/spam claim illustration purposes.

How to programatically get ALL (read and unread) messages from gmail, read status, etc?

I have a customer service web app requirement, which requires that I work pull & integrate data from Gmail, eBay, Amazon, and Paypal. My solution is going to be developed in ASP.Net 4 with C#.
The issue that I'm running into is that my client needs pretty much all of the information that Gmail has about each and every email that comes in & the ATOM feed coming from Gmail seems to be a bit lacking. I realize I can also use POP3 or IMAP, but they too are lacking for a number of reasons.
Specifically, the client needs the read status of emails (whether or not THEY have read emails that were sent to THEM). They also need for all of the filters to remain intact. So if an email is tagged with x,y, & z, then I need to know about it.
The ATOM feed only shows me unread emails, so that's out.
POP3 has no clue (and rightfully so) whether or not they've read an email or not (unless I pull it into a database and manage read status, myself...but that doesn't work if they actually read a mail from within gmail itself).
IMAP seems like it would give me everything I need, but I'm not 100% sure on that. What do you all think? Also, IMAP is SOOO slow. Is anyone aware of any decent libraries that are fairly fast. We're talking about a customer inbox with some 360,000'ish messages at the present time, & the client would prefer to keep those messages at gmail & not work with a disconnected database.
Thoughts / Opinions?
IMAP does provide read/not-read status for each message and you can pull from particular 'labels' (folders) or just pull from the 'all messages' bucket. You don't need to pull the entire message either, you can ask for headers only, giving you the ability to quickly scan many emails.
I've been working on a program to pull my entire gmail dataset down for my own tinkering and processing. I'm using linux, and while there are a multitude of imap 'mirror' and imap 'processing' applications out there, I just want to play with the data, being able to do what I want with it, without stuffing it back into an imap server locally. It's been working decently and I'm using the email's UID (modified slightly) as a file name to dump the headers & email data. Of course, you could massage the data and update a database or whatever at that point, I'm just stashing it for post-processing later. Looking for trends in my email, mostly tinkering.
I tried using the etpan libraries for IMAP processing, didn't find them to my liking, so I've been pulling imap routines from other email programs and servers to play with. I have the RFC's, but really really trying to not reinvent the wheel here if I can help it.
Yup, not the best answer, but hopefully some information to help. I imagine there are nice libraries for PHP, or other web-based systems, I've been working with C++/C myself.

How to generate bounce-back email notification, with some extra info included

I am just now beginning to research this, and so far haven't come up with much. So, I'm hoping you guys can help me, or point me in some sort of direction.
I am in a situation in which I need to somehow be able to detect a failed email delivery and/or bounced-back email. Then, I need to be able to sent out a notification email describing this failure, as well as include some other, specific information in the notification email as well.
At the moment, I really have no idea how to do this. The email system we have now involves some C#.NET managed code, which send the email via an SMTP Exchange server. So, my initial thoughts are that I might be able to use email header information to accomplish this, but I'm not terribly family with all of the available email headers. I am also not at all opposed to finding and using some sort of third-party solution, but again, I'm not familiar with any such solutions or solution providers, and so I am very open to suggestions there too.
Are you using the SMTPClient class? If so, there's a SmtpFailedRecipientsException that would help you accomplish what you need.
Examples and further information given here:
http://msdn.microsoft.com/en-us/library/system.net.mail.smtpfailedrecipientsexception.aspx
Not sure if you want to download messages from an IMAP server or a POP3 server. If it's the case, you may want to check out the Ultimate Bounce Inspector component. It also let you process EML files.
You can use PostMark which allows you to programmatically process bounced emails.

Categories

Resources