Concern to API tool

Peter_1985 2,586 Reputation points
2024-06-18T09:07:52.09+00:00

Hi,

Is there any existing API tool, to be embedded on an ASP page, to receive/send mails on the designated domain, with Email service?

Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,516 questions
ASP.NET API
ASP.NET API
ASP.NET: A set of technologies in the .NET Framework for building web applications and XML web services.API: A software intermediary that allows two applications to interact with each other.
314 questions
{count} votes

4 answers

Sort by: Most helpful
  1. SurferOnWww 2,406 Reputation points
    2024-06-19T00:39:17.5066667+00:00

    Is there any existing API tool, to be embedded on an ASP page, to receive/send mails on the designated domain, with Email service?

    How about SendGrid introduced in the Microsoft document Account confirmation and password recovery in ASP.NET Core?

    0 comments No comments

  2. Neuvi Jiang 545 Reputation points Microsoft Vendor
    2024-06-19T07:58:37.31+00:00

    Hi Peter_1985,

    Thank you for posting in the Q&A Forums.

    In ASP.NET or ASP.NET Core, sending and receiving emails typically involves using the SMTP, POP3, or IMAP protocols, along with the corresponding libraries or APIs. There are no API tools directly embedded on an ASP page to accomplish these tasks, but you can integrate these libraries and APIs to achieve the desired functionality.

    Please note that security and privacy are very important when handling email. Ensure that your application follows best security practices and protects users' privacy and data.

    Best regards

    NeuviJ

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.


  3. AgaveJoe 27,421 Reputation points
    2024-06-19T18:17:25.1333333+00:00

    Does it mean we directly retrieve the mail details from the mail server, right?

    The first step is checking with your email provider. You want find out of your provider has an API. Then learn how the API works by reads their docs. If the email provider does not have an API then you can look into POP3 and IMAP protocol for reading emails.

    POP3 only allows downloading email messages from the server to the client. With IMAP, the emails messages are stored on the server and your code can interact with the server. To learn about IMAP or POP3 or find if anyone has written an IMAP or POP3 client in C# you can search GitHub or do a Google search.

    https://github.com/search?q=imap%20C%23&type=repositories

    0 comments No comments

  4. Lan Huang-MSFT 28,821 Reputation points Microsoft Vendor
    2024-06-21T09:27:59.21+00:00

    Hi @Peter_1985,

    Sorry, you didn't mention your .NET Framework version before, so I assumed you were using the latest version.

    MailKit is not compatible with .NET Framework 4.5.

    User's image

    You can try the following method instead.

    Sending emails in C# with SMTP

    https://video2.skills-academy.com/en-us/dotnet/api/system.net.mail.smtpclient?view=net-8.0

     MailAddress to = new MailAddress("****");
     MailAddress from = new MailAddress("***");
     MailMessage message = new MailMessage(from, to)
     {
         Subject = "Good morning, Elizabeth",
         Body = "Elizabeth, Long time no talk. Would you be up for lunch in Soho on Monday? I'm paying."
     };
     SmtpClient client = new SmtpClient("smtp.server.address", 2525)
     {
         Credentials = new NetworkCredential("smtp_username", "smtp_password"),
         EnableSsl = true
     };
     // code in brackets above needed if authentication required
     try
     {
         client.Send(message);
     }
     catch (SmtpException ex)
     {
         Console.WriteLine(ex.ToString());
     }
    

    Receiving emails is not a part of core C# stack so you will need to utilize some 3rd party libraries for that purpose. OpenPop.NET open-source library seems to be getting the job done in this case. You can use the following code to fetch the topics of incoming mail:

    https://www.nuget.org/packages/OpenPop.NET/

    var client = new Pop3Client();
     client.Connect("pop.gmail.com", 995, true);
     client.Authenticate("piotr@mailtrap.io", "My_password_here");
     var count = client.GetMessageCount();
     Message message = client.GetMessage(count);
     Console.WriteLine(message.Headers.Subject);
    

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.