i using elastic email api in web application project in asp.net c#. when give username , api_key other required data, email sent destination (i sending email myself testing). , on receiving mail, there 1 lable on page "mail sent successfully"
now problem is, if provide wrong username , api_key, lable not mail. know because have provided wrong api_key.
so how check if have provided valid username , api_key can change lable "check data"
my code:
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 provide valid api_keyand debug code, getting response{[36]} . , if provide wrong key, still receive response is, response{[22]} , not mail.
byte[] response = client.uploadvalues("https://api.elasticemail.com/mailer/send", values); if (response.length <= 35) { return null; } else { return encoding.utf8.getstring(response); }
Comments
Post a Comment