This project is a Minimal REST API under .NET 8 for sending e-mails via SMTP from a Contact Form
.
It uses MailKit and MimeKit for constructing and sending emails and Xunit for integration tests.
SendEmail.MinimalAPI_video.mp4
To run this project, you will need:
- .NET 8 SDK
- An SMTP server (environment variables must be set to refer to it)
Clone the repository to your local machine using the following command:
git clone https://github.com/BabylooPro/ContactForm.csharp.git
Navigate to the cloned project's folder:
For the API solution
cd ContactForm.csharp/ContactForm.MinimalAPI
For the Testing solution
cd ContactForm.csharp/ContactForm.Tests
Before launching the application, it is necessary to configure the environment variables. You have two options for creating the .env
file that will contain these variables:
Run the following command in your terminal from ContactForm.csharp/ContactForm.MinimalAPI
to automatically generate the .env
file at the root of the ContactForm.MinimalAPI
project. This command creates the file with the necessary configuration keys, but you will still need to fill them in with the appropriate values.
On macOS and Linux:
echo -e "SMTP_HOST=
SMTP_PORT=
SMTP_EMAIL=
SMTP_PASSWORD=
RECEPTION_EMAIL=" > .env
On Windows (cmd):
(echo SMTP_HOST=& echo SMTP_PORT=& echo SMTP_EMAIL=& echo SMTP_PASSWORD=& echo RECEPTION_EMAIL=) > .env
On Windows (PowerShell):
"SMTP_HOST=`nSMTP_PORT=`nSMTP_EMAIL=`nSMTP_PASSWORD=`nRECEPTION_EMAIL=" | Out-File -FilePath .env -Encoding UTF8
After running the appropriate command for your operating system, open the .env
file and enter the values corresponding to your SMTP configuration next to each key.
Manually create a .env
file at the root of the ContactForm.MinimalAPI solution and add the following lines, replacing the bracketed values with your own SMTP configuration information:
SMTP_HOST=[your_smtp_server]
SMTP_PORT=[smtp_port]
SMTP_EMAIL=[your_smtp_email]
SMTP_PASSWORD=[your_smtp_password]
RECEPTION_EMAIL=[reception_email]
To start working on this project, open it in an IDE compatible with C# and .NET, like Visual Studio, Visual Studio Code, or JetBrains Rider. The IDE should automatically restore NuGet packages and prepare the development environment.
If the packages are not automatically restored, run the following command at the project root:
dotnet build
This command compiles the project, downloads package dependencies specified in the .csproj
file, and prepares everything needed to run the application.
To start the application, run the following command from the ContactForm.MinimalAPI
folder:
dotnet run
The API will be accessible by default on http://localhost:5108
for http and https://localhost:7129
for https.
To send an email, use the /api/email/send-email
endpoint with a POST request containing the following information:
{
"Email": "sender's_email_address",
"Username": "sender's_name",
"Message": "email_message"
}
You can use curl
or a tool like Postman to make this request.
To run the tests, use the following command in folder ContactForm.MinimalAPI from terminal:
dotnet test
This will run all the integration and validation tests defined in the test project.
If you wish to contribute to this project, please fork the repository, make your changes, and submit a pull request for review.
This project is under the MIT License. See the LICENSE file for more details.