Automatically generate email addresses and receive email using C #?

I am a big fan of the email function available in the backpack , where it creates a unique email address on the backpack page and any emails sent to this address will be sent to the page.

My question is how best to create new email addresses and listen to new emails sent to these addresses. I would like to do this from a C # service (I am not using ASP.Net)

  • Has anyone tried to achieve this or something similar before?
  • Are there libraries (preferably FLOSS) that are available or would help me?
  • Can this be done using a cloud-based email service (and if so, what service?) And a library for communicating with this ( OpenPop.Net or similar)?
+4
source share
3 answers

If your mail provider supports setting up wildcard mail in your domain, you can do this with a single email account.

For example, Google Apps for Domains allows you to set *@example.com to myaccount@example.com . When someone sends email messages sales@example.com or contact@example.com , everything will be delivered to myaccount@example.com .

Then this is the process of receiving all emails. Then you look at the to heading in the letter, match it with the name stored in the application for this user, and then process it as you want.

Remember that using this method you will receive spam and other incorrectly addressed emails. You will have to deal with them yourself (for example, by dropping invalid mail that is not addressed to a valid account).

+4
source

I haven’t played a lot with incoming messages, but from the top level this is what you should do.

  • Create email addresses for users based on any logic and save them in the database.

  • Set up a mail server with your domain name and set up one email account as an "all-all" email account. Any emails sent to your domain will fall under this email account if no email address is found.

  • Create a Windows service that will read emails from this "Catch-All" account. There are several libraries for reading emails using POP3 or IMAP.

  • Read the incoming letters to check the email address to which it was sent, compare it with the values ​​stored in the database, and process it accordingly.

Check this question. this can help you with reading your inbox .

+3
source

The goal is not to create email addresses, which is not really happening. What you do is accept email addresses on your system; what you accept is up to you. You can configure the mail server to receive any e-mail sent to your domain, then you can analyze the "Email" field and extract the "name" part. If it corresponds to something you are listening to, then you act accordingly.

I don’t think you will find a library for this particular activity, as it is quite isolated. There are many ways to directly or indirectly receive emails and process them in C #, but I will not consider this because mail processing in .Net is well documented.

+1
source

Source: https://habr.com/ru/post/1334499/


All Articles