Automatically creating email addresses and receiving emails with C#?
Asked Answered
P

3

5

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)?
Pekin answered 6/1, 2011 at 12:26 Comment(1)
those guys have created a mail server and set of libraries to help work with e-mails , lumisoft.ee/lsWWW/ENG/Products/Mail_Server/… hope it helps youJewfish
M
5

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 [email protected]. When someone emails [email protected] or [email protected] it will all be delivered to [email protected].

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).

Moult answered 6/1, 2011 at 12:37 Comment(0)
H
3

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.

Heterozygous answered 6/1, 2011 at 12:42 Comment(0)
S
2

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.

Shiprigged answered 6/1, 2011 at 12:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.