Hi, i am unable to send email for my C# code, although it was working previously and even i am able to send email from PostMan but when the same json is passed from C# code using WebClient it says Forbidden eveytime. Below given is my code snippet.
public static Status SendEmail(ComposeEmail objEmail)
{
Status response = new Status();
string methodUrl = string.Empty;
methodUrl = ConfigurationManager.AppSettings["SMTPURL"];
string json_data = string.Empty;
ComposeEmail obj = objEmail;
obj.fromAddress = ConfigurationManager.AppSettings["supportEmail"];
obj.toAddress = objEmail.toAddress;
obj.ccAddress = "";
obj.bccAddress = "";
obj.subject = objEmail.subject;
string message = "Dear "+objEmail.Name+" <br><br>";
message = message + objEmail.content;
message = message + "<br><br>Regards <br>eSawari Team";
obj.content = message;
obj.mailFormat = "html";
obj.encoding = "UTF-8";
object toReturn = new object();
//converting request into JSON string
var requestJSON = JsonConvert.SerializeObject(obj);
using (var client = new WebClient())
{
client.Headers.Add("Content-Type", "application/json");
client.Headers.Add("Accept", "application/json");
client.Headers.Add("Authorization", ConfigurationManager.AppSettings["EmailAuth"].ToString());
try
{
json_data = client.UploadString(methodUrl, HttpMethod.Post.ToString(), requestJSON);
response.Code = HttpStatusCode.OK;
response.Message = "Successful";
}
catch (System.Net.WebException ex)
{
response.Code = ((System.Net.HttpWebResponse)(ex.Response)).StatusCode;
response.Message = ((System.Net.HttpWebResponse)(ex.Response)).StatusDescription;
}
catch (Exception ex)
{
response.Code = HttpStatusCode.InternalServerError;
response.Message = ex.Message;
}
}
return response;
}