email_verification 1.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package email_verification --version 1.1.0                
NuGet\Install-Package email_verification -Version 1.1.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="email_verification" Version="1.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add email_verification --version 1.1.0                
#r "nuget: email_verification, 1.1.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 email_verification as a Cake Addin
#addin nuget:?package=email_verification&version=1.1.0

// Install email_verification as a Cake Tool
#tool nuget:?package=email_verification&version=1.1.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.
  • Get the Validation Status

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.1.8 134 9/17/2024
1.1.7 116 9/6/2024
1.1.6 116 7/24/2024
1.1.5 100 7/24/2024
1.1.4 117 7/22/2024
1.1.3 113 7/22/2024
1.1.2 109 7/20/2024
1.1.1 112 7/20/2024
1.1.0 88 7/8/2024
1.0.0 115 7/20/2024