code to configure (API_KEY) in appsetting.json & email.cs using C# web api
without using (ConfigurationManager.AppSettings[API_KEY]) in email.cs
code to configure (API_KEY) in appsetting.json & email.cs using C# web api
without using (ConfigurationManager.AppSettings[API_KEY]) in email.cs
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jaimin ShethiyaPosted Mar 28, 2024, 5:20 AM
Hello Meghna,
In the Constant.ApiKey need to double check.
And also check the configuration you have to resolve in the constructor side in your class.
Thanks
Meghana MPosted Jan 25, 2024, 11:20 AM
I have declared in appsetting.json as below
"MailjetSettings": { "ApiKey": "YOUR_API_KEY", "ApiSecret": "YOUR_API_SECRET" }
In email.cs ,i'm using as below
string API_KEY = _configuration.GetValue(Constants.ApiKey);
It is throwing error for _configuration
Jayraj ChhayaPosted Jan 25, 2024, 11:10 AM
To configure the MAILJET mail service in C#, you can follow these steps:
Install the Mailjet NuGet package in your project. You can do this by right-clicking on your project in Visual Studio, selecting "Manage NuGet Packages," and searching for "Mailjet" in the NuGet Package Manager.
Once the package is installed, you need to configure the API key in the appsettings.json file. Open the appsettings.json file and add the following section:
Replace "YOUR_API_KEY" and "YOUR_API_SECRET" with your actual Mailjet API key and secret.
Make sure you have the necessary using statements at the top of the file:
Now you can access the API key and secret from the _mailjetSettings object in your email service methods.