[英]How to check if API key of Elastic Email API is correct or incorrect in asp.net and C#
I am using Elastic Email API in my web application project in asp.net c#. 我在asp.net c#的Web应用程序项目中使用Elastic Email API。 when I give
USERNAME
and API_KEY
with other required data, email is sent to destination (I am sending email to myself for testing). 当我将其他必需的数据提供给
USERNAME
和API_KEY
时,电子邮件将发送到目的地(我正在向自己发送电子邮件以进行测试)。 And on receiving mail, there is one Lable
on my page "Mail is sent successfully"
在接收邮件时,我的页面上有一个
Lable
"Mail is sent successfully"
Now the problem is, if I provide wrong USERNAME
and API_KEY
, I will get Lable
but not mail. 现在的问题是,如果我提供了错误的
USERNAME
和API_KEY
,我会得到Lable
而不是邮件。 I know because I have provided wrong API_KEY
. 我知道,因为我提供了错误的
API_KEY
。
So how to check if i have provided valid USERNAME
and API_KEY
so that I can change Lable to "check your data"
因此,如何检查我是否提供了有效的
USERNAME
和API_KEY
以便可以更改Lable以"check your data"
My Code: 我的代码:
ElasticEmail.cs ElasticEmail.cs
public static string SaveAndTestElasticEmail(string from, string to, string fromName, string subject, string bodyHtml)
{
try
{
setElasticEmailSettings();
string channel = System.Configuration.ConfigurationManager.AppSettings["registrationNumber"];
WebClient client = new WebClient();
NameValueCollection values = new NameValueCollection();
values.Add("username", USERNAME);
values.Add("api_key", API_KEY);
values.Add("from", from);
values.Add("from_name", fromName);
values.Add("subject", subject);
values.Add("body_html", bodyHtml);
values.Add("channel", channel);
values.Add("to", to);
byte[] response = client.UploadValues("https://api.elasticemail.com/mailer/send", values);
return Encoding.UTF8.GetString(response);
}
catch (Exception ex)
{
return null;
}
}
If I provide valid API_KEY
and I debug my code, I am getting response{[36]}
. 如果我提供了有效的
API_KEY
并调试了代码, API_KEY
得到response{[36]}
。 and if I provide wrong key, then still I will receive response but it is, response{[22]}
and I will not get mail. 如果我提供了错误的密钥,那么我仍然会收到响应,但是它是
response{[22]}
并且不会收到邮件。
byte[] response = client.UploadValues("https://api.elasticemail.com/mailer/send", values);
if (response.Length <= 35)
{
return null;
}
else
{
return Encoding.UTF8.GetString(response);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.