Concern to API tool

Peter_1985 2,686 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.
13,191 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.
341 questions
{count} votes

5 answers

Sort by: Most helpful
  1. SurferOnWww 3,066 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 1,375 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 28,456 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 29,666 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://learn.microsoft.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.


  5. Peter_1985 2,686 Reputation points
    2024-07-09T03:07:08.8733333+00:00

    I want to know the reason to the following. Currently, I am using smtp.domain1.org (not mail.domain1.org). Must I use mail.domain1.org?

    -Q-

    The server did not respond with a + response. The response was: "220 mail.domain1.org ESMTP"

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: OpenPop.Pop3.Exceptions.PopServerException: The server did not respond with a + response. The response was: "220 mail.domain1.org ESMTP"

    Source Error:

    Line 527: var client = new Pop3Client();

    Line 528: client.Connect("smtp.domain1.org", 587, false);

    Line 529: client.Authenticate("jane@domain1.org", "?");

    -UQ-


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.