Muhammad Faizan Khatri
Muhammad Faizan Khatri

Reputation: 643

Best Approach to Receive Email of a particular account under asp.net core

We need to setup a mechanism of receiving email of a particular Account of a Domain, Just like normal ticketing system reply emails.

Found some of the sources of how it could be achieved.

Either Go For Custom Solution

https://github.com/jstedfast/MailKit

https://joshwright.com/tips/tips-sending-receiving-email-in-csharp/

Send Grid Web Hooks

The Other Ready to go solution is Send Grid, but the problem with send grid is it monitors each and every email of domain, i can filter them at my end but still it doesn't seem good approach keeping the security prospect in mind. Here our Approach could be , can create a sub domain under the domain and receive those emails

I am currently using send grid for sending emails

Looking forward , what could the best, reliable and scalable approach and the pros and corns of it.

Upvotes: 3

Views: 1804

Answers (1)

Ken Lee
Ken Lee

Reputation: 8063

Simply write a C# program to receive emails of that particular box as follows:

var client = new POPClient();
client.Connect("pop.gmail.com", 995, true);
client.Authenticate("[email protected]", "YourPasswordHere");

var count = client.GetMessageCount();

// use a for loop to get the subject / message
Message message = client.GetMessage(count);

Console.WriteLine(message.Headers.Subject);

// message.Headers.From.Address; 
// from address
// messagePart.BodyEncoding.GetString(messagePart.Body);
// message body

modify the above program so that, after receiving the email, the system

  1. inject the subject and message into a db record
  2. generate a ticket number
  3. reply to the sender that a ticket (# xxxxxx) has been issued
  4. follow up all the correspondence using this ticket (store all the correspondence in the db record)

Upvotes: 3

Related Questions