我在asp中的web应用程序项目中使用弹性电子邮件API。net c#。
当我付出
USERNAME
和
API_KEY
与其他所需数据一起,电子邮件被发送到目的地(我正在向自己发送电子邮件以进行测试)。在收到邮件时
Lable
在我的页面上
"Mail is sent successfully"
现在的问题是,如果我提供了错误的
用户名
和
API_键
,我会得到
拉布勒
但不是邮件。我知道,因为我提供了错误的
API_键
.
那么如何检查我是否提供了有效的
用户名
和
API_键
这样我就可以把Lable改成
"check your data"
我的代码:
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;
}
}
如果我提供有效
API_键
我调试代码
response{[36]}
。如果我提供了错误的密钥,那么我仍然会收到响应,
response{[22]}
我不会收到邮件。