The SMTPClient Library is a C# .NET Framework library designed to provide an SMTP client functionality for reading messages from an email server and sending emails to recipients. The library includes two main classes: SMTPClient
and SMTPHelper
.
The SMTPClient
class provides functionalities for connecting to an email server, retrieving email messages, and sending emails to recipients. It utilizes the MailKit library to interact with the IMAP protocol for reading email messages.
EmailClient
: An instance of theImapClient
class from the MailKit library used to connect to the email server.MessageList
: A list ofMimeMessage
objects to store retrieved email messages.EmailListReceived
: A list ofEmailListEntity
objects containing email addresses and their corresponding display names for received messages.AnswerEmailList
: A list ofEmailListEntity
objects containing email addresses and their corresponding display names for sending emails.
SMTPClient()
: Constructor for initializing theSMTPClient
class. It connects to the email server and retrieves email messages.GetMessageList()
: Retrieves email messages from the email server and adds them to theMessageList
.
The SMTPHelper
class provides helper methods used by the SMTPClient
class for sending emails. It utilizes the SmtpClient
class from the System.Net.Mail namespace for sending emails via the SMTP protocol.
BackupMsg
: A backup instance of theMailMessage
class to handle cases where the primary email sending fails.ClientReceiveUsername
: Username for connecting to the email server to retrieve messages.ClientReceivePassword
: Password for connecting to the email server to retrieve messages.ClientSendUsername
: Username for sending emails via SMTP.ClientSendPassword
: Password for sending emails via SMTP.BackupClientSendUsername
: Backup username for sending emails in case of failure.BackupClientSendPassword
: Backup password for sending emails in case of failure.LogEmailList
: A collection of email addresses used for email logging purposes.GetEmailsHrBack
: The number of hours to retrieve email messages from the past.EmailListEntity
: A helper class representing an email address and its display name.
SMTPSend()
: Sends an email using theSmtpClient
and provides backup email sending functionality in case of failure.SMTPLogSend()
: Sends an email for logging purposes using theSmtpClient
.ClientConnect()
: Connects to the email server for email retrieval.SendEmail()
: Composes and sends an email with the provided message.
The SMTPClient library provides functionalities for reading email messages and sending emails. To use the library, follow the steps below:
- Instantiate the
SMTPClient
class to connect to the email server and retrieve messages. - Use the methods provided by the
SMTPClient
class to read email messages and handle them as needed. - To send emails, utilize the methods provided by the
SMTPHelper
class for email composition and sending.
Contributions to this project are welcome. If you find any issues or want to suggest improvements, please feel free to create a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.