NetsenGroup.Util.email_verification 1.0.0

Suggested Alternatives

email_verification

dotnet add package NetsenGroup.Util.email_verification --version 1.0.0                
NuGet\Install-Package NetsenGroup.Util.email_verification -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NetsenGroup.Util.email_verification" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NetsenGroup.Util.email_verification --version 1.0.0                
#r "nuget: NetsenGroup.Util.email_verification, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install NetsenGroup.Util.email_verification as a Cake Addin
#addin nuget:?package=NetsenGroup.Util.email_verification&version=1.0.0

// Install NetsenGroup.Util.email_verification as a Cake Tool
#tool nuget:?package=NetsenGroup.Util.email_verification&version=1.0.0                

Email Validation Library

This C# library allows you to validate email addresses, send verification emails, and confirm registered email addresses in a database.

Prerequisites

  • .NET version >= 2.1

Features

  • Email address validation: Verify if an email address is in a valid format.
  • Sending verification emails: Send a verification email with a validation code to a given email address.
  • Email address confirmation: Verify the validation code submitted by the user and confirm the email address if the code is valid and not expired.

Installation

  1. Download and install the "MailKit" NuGet package (version 2.6.0 or later) for email management.

  2. Download and install the "Microsoft.Data.SqlClient" NuGet package (version 4.1.0 or later) for SQL Server database management.

  3. Add the email validation library to your project by referencing the DLL or project.

Usage

Configuration

Before using the library, you need to configure the SQL Server database connection string and specify the table name used to store email addresses and validation codes. You can do this by setting the static properties ConnectionString and TableName of the EmailValidator class. For example:

EmailValidator.ConnectionString = "YourConnectionString";
EmailValidator.TableName = "YourTableName";
EmailValidator.ExpirationCodeTime = 15; // in minutes
  • The default table name is ValidationEmails, and the default code expiration time ExpirationCodeTime is 15 minutes.

Email Address Validation

To validate an email address, simply call the static method ValidateEmail of the EmailValidator class. For example:

bool isValid = EmailValidator.ValidateEmail("test@example.com");

Sending Verification Email

To send a verification email with a validation code, call the static method SendMailVerification of the EmailValidator class. Make sure to provide the required SMTP credentials in the CredentialModel object. For example:

CredentialModel credential = new CredentialModel
{
    Name = "YourCompany",
    Email = "your-email@example.com",
    Host = "smtp.example.com",
    Port = 587,
    Password = "YourPassword"
};

string emailTo = "test@example.com";
string linkRedirect = "https://yoursite.com/confirmation-email";
EmailResponse response = EmailValidator.SendMailVerification(emailTo, credential, linkRedirect);

if (response.IsValid)
{
    // The validation code has been successfully sent and stored in the database.
}
else
{
    // An error occurred while sending the email.
    // Display the error message from the response.
    Console.WriteLine(response.Message);
}

Email Address Confirmation

To confirm an email address using the received validation code, call the static method ConfirmMail of the EmailValidator class. For example:

string emailToConfirm = "test@example.com";
string validationCode = "ABC123";
ConfirmEmailResponse confirmResponse = EmailValidator.ConfirmMail(emailToConfirm, validationCode);

if (confirmResponse.IsConfirmed)
{
    // The email address has been successfully confirmed.
    // The database has been updated to mark the email address as confirmed.
}
else
{
    // An error occurred while confirming the email address.
    // Display the error message from the response.
    Console.WriteLine(confirmResponse.Message);
}

Disclaimer

Before using this library in production, ensure that you have properly configured your database and SMTP server for email delivery. Use secure configuration settings for credentials and avoid storing passwords in plaintext.

Acknowledgments

This library uses the "MailKit" and "Microsoft.Data.SqlClient" NuGet packages for email and database management, respectively. We thank the developers of these packages for their excellent work.

Contributors

License

This library is distributed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 183 8/22/2023 1.0.0 is deprecated because it is no longer maintained.